r/cpp • u/anonymous23874 • Apr 19 '20
Default function arguments are the devil
https://quuxplusone.github.io/blog/2020/04/18/default-function-arguments-are-the-devil/
90
Upvotes
r/cpp • u/anonymous23874 • Apr 19 '20
View all comments
Show parent comment
4
u/Gotebe Apr 19 '20
In your second paragraph, you really give an argument against poor code change and poor code in general, not so much against default parameters.
In overloads situation, the new parameter that alters the behavior means that the code is already bad. It is bad because that one variant being different is not how overloads are used. Surely foo(p1, p2) and foo(p1, p2, p3) cannot possibly mean "explode" and "implode", respectively? (I know, I exaggerate...) Next, even with overloads, if they do the same with variants, chances are, they should be one thing with variations, not a copy-paste.
On the other hand, he who added another default parameter, but made a bug, we'll, they made a bug.