r/cpp • • 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

149 comments sorted by

View all comments

Show parent comment

9

u/NilacTheGrim Apr 19 '20

Hmm. The problem I think you're talking about really is just poorly designed APIs and/or sloppy programmers using the APIs without understanding them. In a word: stupidity.

Small things like deleting default function arguments from a language or forbidding them in an organization will not solve ... stupidity. Stupidity runs deep and has a long history. Default arguments or not... stupidity finds a way.

2

u/cat_vs_spider Apr 19 '20

Stupidity does find a way, but I think default parameters are a feature that exist pretty much to facilitate stupidity. In my experience, they are always used to bolt some new behavior onto a new function that everybody is used to working a certain way, thereby pulling the rug out from under them. And since they must be the last arguments, they result in function arguments not being organized in a clean way (fungus growth pattern). And god help you if you want to customize the fifth default argument.

3

u/NilacTheGrim Apr 19 '20

I mean just like with everything there's a way to do them right and a way to do them wrong. Again, I say -- your argument is with bad design and bad APIs. They find a way to exist everywhere. I don't think default arguments are a problem per se.