3 ms·
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,
by darklajid 11y ago
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);
- mortoray 11y agoYes, named arguments are a nice solution. Espeically if it can be forced (only passable by name).
- reacweb 11y agoYou may love Ada: function Calc_Formula(A, B : Integer; Is_Gain : Boolean) return Float is ... X : Float := Calc_Formula(4, 5, Is_Gain => True);
- darklajid 11y agoActually 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.
- jtheory 11y agoI'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.