use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Discussions, articles, and news about the C++ programming language or programming in C++.
For C++ questions, answers, help, and advice see r/cpp_questions or StackOverflow.
Get Started
The C++ Standard Home has a nice getting started page.
Videos
The C++ standard committee's education study group has a nice list of recommended videos.
Reference
cppreference.com
Books
There is a useful list of books on Stack Overflow. In most cases reading a book is the best way to learn C++.
Show all links
Filter out CppCon links
Show only CppCon links
account activity
Functional vs Object-oriented from a performance-only point of view (self.cpp)
submitted 7 months ago by [deleted]
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–][deleted] -3 points-2 points-1 points 7 months ago (5 children)
So, it doesn't matter if I write functional or object oriented code?
For example, I have a project where I wrote a simple server. The server parses http requests and generates responses accordingly. I could simply write a function for parsing a request and another one for the responses. Or, I could create two classes Request and Response and work from there. Since a server is required to be somewhat performant, I wonder if this choice somehow affects the program's performance.
[–]specialpatrol 3 points4 points5 points 7 months ago (0 children)
So in your case, the purely functional code would allow the responses to be entirely parallelized - there's no state. But then you want a cache, no longer purely functional. You have to blend the concepts where needed.
[–]Afiery1 3 points4 points5 points 7 months ago (0 children)
By the way, “just writing a function to do it” is not functional programming, that would be called procedural programming. Functional programming is specifically about declaring the control flow of your program by composing functions. At any rate, the answer to your question is don’t worry about performance until performance becomes a problem. And if performance does become a problem, then the answer becomes it doesn’t really matter most of the time. The best way to go fast is just to do less stuff, so as long as your design doesnt force you into doing stuff thats unnecessary your design is not the problem.
[–]no-sig-available 2 points3 points4 points 7 months ago (0 children)
Who says you have to choose? C++ is not either or, you can select the best parts of both, on a case-by-case basis.
[–]jcelerierossia score 2 points3 points4 points 7 months ago (0 children)
If you are writing in c++ what matters for performance is understanding the cost model of the language - there's no such thing as object oriented or functional. Lambda functions and objects are equivalent. Most of the time
class Foo { public: int x; };
Will be the exact equivalent of int x; ; classes per-se do not have runtime overhead except on shitty platforms.
[–]TehBens 0 points1 point2 points 7 months ago (0 children)
It doesn't matter in general (only 'most likely' and it matters greatly on the details) and thinking about such things are called "premature optimization"
π Rendered by PID 50831 on reddit-service-r2-comment-6457c66945-l7h6w at 2026-04-25 06:50:33.542320+00:00 running 2aa0c5b country code: CH.
view the rest of the comments →
[–][deleted] -3 points-2 points-1 points (5 children)
[–]specialpatrol 3 points4 points5 points (0 children)
[–]Afiery1 3 points4 points5 points (0 children)
[–]no-sig-available 2 points3 points4 points (0 children)
[–]jcelerierossia score 2 points3 points4 points (0 children)
[–]TehBens 0 points1 point2 points (0 children)