Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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);


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);


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.




Consider applying for YC's Winter 2027 batch! Applications are open till November 2.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: