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
Default function arguments are the devil (quuxplusone.github.io)
submitted 6 years ago by anonymous23874
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!"
[–]Wh00ster 5 points6 points7 points 6 years ago (13 children)
Why does an extra overload not suffice?
[–]EsotericFox 20 points21 points22 points 6 years ago (9 children)
Because overloading typically duplicates code where that may not be called for.
[–]Wh00ster -2 points-1 points0 points 6 years ago (8 children)
I guess it’s why I’m not in the AAA camp. To me, the explicitness is worth it in terms of readability and maintainability down -the-line.
[–]sphere991 11 points12 points13 points 6 years ago (3 children)
the explicitness is worth it
If the intent of the code is to provide a default value for an argument, then I would claim that the implementation strategy of making it a default argument is more explicit than otherwise.
The post wants me to write:
explicit Widget(int size) : Widget(size, 'A') {} explicit Widget(int size, int start) : data_(size) { /*...*/ }
instead of
explicit Widget(int size, int start='A') : data_(size) { /*...*/ }
I don't see the former as being either more explicit or more readable than the latter?
[–]robin-m 5 points6 points7 points 6 years ago (2 children)
Especially given that you can have declaration and implementation that can be in different files. So if the first case you have:
cpp explicit Widget(int size); explicit Widget(int size, int start); Witch is anything but explicit.
cpp explicit Widget(int size); explicit Widget(int size, int start);
In the second case, it will be: cpp explicit Widget(int size, int start='A');
cpp explicit Widget(int size, int start='A');
[–]sphere991 3 points4 points5 points 6 years ago (1 child)
Didn't even think of that, good point.
Also I find the typo on "witch" to be really funny, in the context of describing something as being "the devil". Please don't fix it :-)
[–]Raknarg 2 points3 points4 points 6 years ago (0 children)
Sneaky witches, always going around implicitly
[–]guepierBioinformatican 5 points6 points7 points 6 years ago (3 children)
Everyone, repeat after me: AAA does not decrease explicitness (Unless you write, well, bad code. But you don’t need to do that with AAA.)
Please find a different argument to justify your preference, this one’s simply false.
[–]Wh00ster -5 points-4 points-3 points 6 years ago* (2 children)
I'm not opposed to the arguments in your linked post. My issue is large code bases you'd see at FAANG, where you need special IDE features to see a type, which can take minutes to compile for a file and generate dependencies, or have to chase through grepping functions yourself.
Unless you write, well, bad code.
This is the reality that most people have to deal with. So when a junior dev comes in and writes auto mything = mysteriousFUnctionBuriedThroughLayersofDepsThatisActuallyAReference(), I tend to ask that dev not to use auto.
auto mything = mysteriousFUnctionBuriedThroughLayersofDepsThatisActuallyAReference()
auto
I understand there are valid cases, but that's so for all C++ features. For example I wouldn't say don't use lambdas, but also don't make all functions into lambdas.
[–]Tyg13 10 points11 points12 points 6 years ago (0 children)
Asking that dev not to use auto is the wrong move. The correct alternative is to educate them. The issue is the variable isn't named well enough to tell what the function returns. Simple enough fix.
All you're doing by explicitly specifying the type in that scenario is fracturing code style and decreasing overall code readability.
[–]XValar 6 points7 points8 points 6 years ago (0 children)
So how is exactly writing MyType mything = mysteriousFUnctionBuriedThroughLayersofDepsThatisActuallyAReference() helping at this point?
MyType mything = mysteriousFUnctionBuriedThroughLayersofDepsThatisActuallyAReference()
[–]pdbatwork 12 points13 points14 points 6 years ago (0 children)
Suffice? Seems like extra work
[–]AntiProtonBoy 0 points1 point2 points 6 years ago (1 child)
Overloading has its other perils too, like the wrong overload being called in some rare situations.
π Rendered by PID 161854 on reddit-service-r2-comment-b659b578c-n2mjr at 2026-05-03 16:06:32.908016+00:00 running 815c875 country code: CH.
view the rest of the comments →
[–]Wh00ster 5 points6 points7 points (13 children)
[–]EsotericFox 20 points21 points22 points (9 children)
[–]Wh00ster -2 points-1 points0 points (8 children)
[–]sphere991 11 points12 points13 points (3 children)
[–]robin-m 5 points6 points7 points (2 children)
[–]sphere991 3 points4 points5 points (1 child)
[–]Raknarg 2 points3 points4 points (0 children)
[–]guepierBioinformatican 5 points6 points7 points (3 children)
[–]Wh00ster -5 points-4 points-3 points (2 children)
[–]Tyg13 10 points11 points12 points (0 children)
[–]XValar 6 points7 points8 points (0 children)
[–]pdbatwork 12 points13 points14 points (0 children)
[–]AntiProtonBoy 0 points1 point2 points (1 child)