News for hackers. Stuff that matters.
Re:Get rid of boolean function parameters by jjaredsimpson on Monday June 15, 2015 @08:44AM (#9718939)
Why not just use named parameters at the call site instead?

    DoSomething(thing, logging: true);
Re:Get rid of boolean function parameters by ColinDabritz on Monday June 15, 2015 @09:53AM (#9719248)
I definitely like this approach in my own code. I think the main advantage of a different approach such as enums is enforcing the explicitness at the call site for all users, especially in library functions.

Another thing to consider: In some cases, it may make more sense to split the function into two versions, one for 'true' and one for 'false'. Then you gain the enforced explicitness. The function could call a private method to share code and pass the Boolean. Clearly that isn't ideal for all situations, but it might help in some situations today.

Re:Get rid of boolean function parameters by JadeNB on Monday June 15, 2015 @11:06AM (#9719777)
> Another thing to consider: In some cases, it may make more sense to split the function into two versions, one for 'true' and one for 'false'. Then you gain the enforced explicitness. The function could call a private method to share code and pass the Boolean.

The author describes exactly this approach and implementation, under the heading "Distinct functions".

Re:Get rid of boolean function parameters by Kesty on Monday June 15, 2015 @09:04AM (#9719017)
That's what we usually do in C#.

Required parameters as positional, and optional as named.

doSomething(req_param_1_value, req_param_2_value, optional_param_1 : value, optional_param2: value);