News for hackers. Stuff that matters.
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.

    float CalcFormula(int a,int b, bool isGain) {..}

    var x = CalcFormula(4, 5, isGain: true);
Re:Get rid of boolean function parameters by jtheory on Monday June 15, 2015 @08:07AM (#9718802)
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.
Re:Get rid of boolean function parameters by mortoray on Monday June 15, 2015 @06:43AM (#9718545)
Yes, named arguments are a nice solution. Espeically if it can be forced (only passable by name).
Re:Get rid of boolean function parameters by reacweb on Monday June 15, 2015 @07:40AM (#9718708)
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);
Re:Get rid of boolean function parameters by darklajid on Monday June 15, 2015 @11:39AM (#9720024)
Actually that was 'real' C#, so the language I'm working with does support this feature.

That said, Ada is certainly something I want to learn more about at some point.