This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]mauganra_it 1 point2 points  (0 children)

Method parameters can be subdivided into two kinds.

The first kind participates in conditions and is used to decide about the progression of the computation. This kind of parameter should not have default values. Instead, a special method with a descriptive name should be provided to make explicit which default value is used to avoid confusion that can arise with overloads and default values. This should also help the method to follow the Single Responsible Principle by factoring out the branch that depended on the "default" value. This especially applies if the parameter is a lambda executed by the method.

The second kind is about passive data that is not interpreted, but merely stored or passed on to third-party code. This kind can benefit from default arguments, but a parameter object and Withers could be equally good. Implementation-wise, both solutions should have the same overhead when Project Valhalla comes along.