News for hackers. Stuff that matters.
Re:Get rid of boolean function parameters by greggman on Monday June 15, 2015 @10:06AM (#9719320)
So I get that

    calc_formula(a, b, false) 
Is unclear but so are `a` and `b`

    ctx.arc(100, 200, 300, 0, Math.PI*2, false)
or

    gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGB, 100, 200, 0,
                  gl.RGBA, gl.UNSIGNED_BYTE, null);
How are those examples any more self documenting? I don't see anything special about boolean anymore than the other arguments. If you really want your code to be clear (and I'm not saying I do this) you'd need to either use a language that allows naming every argument or else put every argument in a variable with a descriptive name

    var centerX = 100;
    var centerY = 200;
    var radius = 300;
    var arcStartRadians = 0;
    var arcEndRadians = Math.PI * 2;
    var counterClockwise = false;
    ctx.arc(centerX, centerY, radius,
            arcStartRadians, arcEndRadians,
            counterClockwise);
Re:Get rid of boolean function parameters by paulmd on Monday June 15, 2015 @10:35AM (#9719533)
I'll say that I do that (define constants to variables/consts/#DEFINE/etc and then use them as arguments), and I do it for exactly the reasons you describe. I also try to make magic numbers as self-explanatory as possible - rather than (say) use the number 84600 I'll write 60 * 60 * 24 for when I want the number of seconds per day.

It's way easier to remember what's going on when you come back a year later, and all but the simplest compilers will be smart enough to bash it down to constant parameters if that's possible.

Yeah, more lines of code, but I think readability trumps terseness (within reason). Some functions just use a bunch of parameters and it's not really the extra line to name the parameter that's causing the issue. Also if you're using an editor that does code folding you could just fold that block away.

Re:Get rid of boolean function parameters by chrisheller on Monday June 15, 2015 @10:50AM (#9719658)
I'm not sure if the transposition was intended, but your comment shows another reason why using a calculated value here is good.
Re:Get rid of boolean function parameters by JadeNB on Monday June 15, 2015 @10:59AM (#9719730)
Doesn't Smalltalk have a convention whereby the name of the function specifies the purpose of the variables, like

    arcWithCenterX: withCenterY:
or similar? (I vaguely recall this, but can't find any examples online.)
Re:Get rid of boolean function parameters by jurip on Monday June 15, 2015 @11:14AM (#9719826)
Yeah, and Objective-C and now Swift inherited that same convention.

Objective-C:

    [self frob:param1 withObject:param2];
Swift:

    self.frob(param1, withObject:param2)
Re:Get rid of boolean function parameters by protomyth on Monday June 15, 2015 @11:50AM (#9720103)
after going through and starting to learn Swift, I really wish

  self.frob(param1, withObject:param2)
could be written as

  self.[frob:param1 withObject:param2]
Re:Get rid of boolean function parameters by cnvogel on Monday June 15, 2015 @10:45AM (#9719613)
Personally, I tend to put the function arguments' names from the API documentation in comments if its kind of obscure or I guess that I'll forget if I need to revisit this piece of code. As in...

    texImage2D(100, 200, 300,
        0 /*start*/, Math.PI*2 /*end*/, /*ctrClockwise*/ false);