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
11
u/the_poope Apr 19 '20
I use them only in cases where the parameter really is optional. For instance some numerical algorithm might have some tweaking parameter. One could hardcode a default value that give good performance in most cases, but in rare cases you may want to choose another value. If you use default argument for this parameter you have ar the same time documented what the default is, whereas in the case where it is a hardcoded internal value, the user will never know what value is used.