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
0
u/ilep Apr 19 '20 edited Apr 19 '20
If you really really want to, you could use ellipsis (...) and add some way to parse arguments yourself in the function. But that would be horribly complicated. And it really misses entirely the point of what function prototype/API are supposed to be.
Interface should be clean, simple and well defined in any application. If it is not it is a poorly designed interface. Simply adding helper function (with overloading) for calling some other function is simpler and more obvious when you don't want to define all parameters and you can often find where that variant is called with the tools in IDE. Tracking back callers with some argument named at caller would not be quite so obvious.
Yes, default arguments can have their uses but overusing it results in bad designs.