Re:Get rid of boolean function parameters
by darklajid on Monday June 15, 2015 @06:13AM
(#9718452)
That comes up again and again. For me, named arguments solve that problem.
[ Parent
| on HN ]
I'm mostly coding in Java, which doesn't have named params... but I don't like either extra variable declarations just for this, nor mysterious booleans.
My current habit is to use comments for non-enforced named params; e.g.,
fetchLatestFoo( long barId, false/*fetchContent*/ );
No compile-time checking, etc., but it still serves the purpose.Yes, named arguments are a nice solution. Espeically if it can be forced (only passable by name).
You may love Ada:
function Calc_Formula(A, B : Integer; Is_Gain : Boolean) return Float is ...
X : Float := Calc_Formula(4, 5, Is_Gain => True);