Problems with default function arguments (2020)
Sure, the pitfalls are real. But they have benefits too. A fair assessment should examine both sides before coming to a decision, not just one. Off the top of my head, these come to mind:<p>- Defaults avoid having to duplicate the rest of the function (everything outside the body braces) just for the sake of an additional parameter. It might not be a big deal for reset() which is simple and only takes one argument anyway, but for other functions it can be a lot of boilerplate to keep in sync with the main overload: everything from the documentation, templates, parameter names, parameter types, etc. needs to be duplicated and kept in sync.<p>- Without default arguments, you lose the ability to capture parameters by-value with guaranteed move&#x2F;copy elision. You have to capture by reference and then construct at least one instance that you otherwise be able to elide. Sure, you don&#x27;t need that performance all the time, but that&#x27;s not the point. The point is there are times when you do.<p>- &quot;Go to definition&quot; in your IDE goes directly to the place you care about; &quot;find all references&quot; finds all references directly.<p>- Optionals are just way easier to read. Otherwise every reader or maintainer must read every other parameter and ensure they&#x27;re all forwarded 1:1 without side effects to understand if the semantics of the call are identical with the optional parameter supplied explicitly.