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

5

u/spanishgum Apr 19 '20

Default arguments can definitely be abused. I think programmers sometimes fail to see beyond their own use cases and think defaults will provide convenience. It’s probably true in general contexts, but not all.

12

u/EsotericFox Apr 19 '20

Agreed, but that's a decision that must be weighed.

Do I need to expose this behavior? Would it be better to have these functions live elsewhere?

Depending on the answer, you may still very well have a solid argument for needing/using default arguments. And if you don't, you have a solid case for refactoring or redesign.