I think most of this article is a load of nonsense, myself.
<https://www.infoworld.com/article/3990923/booleans-considered-harmful.html>
Thoughts?
On 22/05/2025 08:51, Lawrence D'Oliveiro wrote:
I think most of this article is a load of nonsense, myself.
<https://www.infoworld.com/article/3990923/booleans-considered-harmful.html> >>
Thoughts?
Yeah, it's mostly balderdash, especially the "think positive"
part: rules of dumb I call those, in fact reinventing the wheel
and reinventing it wrong.
But we know better: the one best practice that would be relevant
there is *do not use magic values*. And of course we could rather
say more about that. And of course it still wouldn't be just a
rule of dumb, rather learn the art of *incremental/evolutionary*...
I think most of this article is a load of nonsense, myself.
<https://www.infoworld.com/article/3990923/booleans-considered-harmful.html>
Thoughts?
On 22/05/2025 13:51, David Brown wrote:
On 22/05/2025 08:51, Lawrence D'Oliveiro wrote:
I think most of this article is a load of nonsense, myself.
<https://www.infoworld.com/article/3990923/booleans-considered-harmful.html>
Thoughts?
He makes some relevant points about clarity of code,
He makes no relevant points: the whole thing is rather misguided.
<snip>
So in general, I'd prefer positive names to negative ones -
"UserIsAuthorised" rather than "UserIsNotAuthorised". And I would not
"hide" a "not" in the middle of a variable name as his example does.
But sometimes a negative name makes more sense - "UserBanned" might be
perfectly reasonable.
All things being equal, I'd usually choose "put positive first". But
again, that's more a bias than a rule. In particular, it might often
be best with an "early exit" coming first regardless of whether it is
the positive condition or the negative condition.
I could give tons of *sensible* examples where you'd have to say
"sure, maybe, in that case". Rather, some properties and conditions
are *most naturally* expressed negatively. Keep also in mind that readability is way more about uniformity than the specifics, hence
some of those are/were indeed common conventions then patterns. --
More on that line in my initial post.
That said, "think positive", as the "think negative" of some of
your counter-examples, is only *dumb and dumbing*: perfectly in
line with the abolishment of negation and the dumbing down of
humanity, as negation is the fundamental logical connective...
Not that I expect *you* and the resident gang to acknowledge
any of that, of course: you cannot even engage properly.
Anyway, HTH.
On 22/05/2025 08:51, Lawrence D'Oliveiro wrote:
I think most of this article is a load of nonsense, myself.
<https://www.infoworld.com/article/3990923/booleans-considered-harmful.html> >>
Thoughts?
He makes some relevant points about clarity of code,
So in general, I'd prefer positive names to negative ones - "UserIsAuthorised" rather than "UserIsNotAuthorised". And I would not "hide" a "not" in the middle of a variable name as his example does. But sometimes a negative name makes more sense - "UserBanned" might be
perfectly reasonable.
All things being equal, I'd usually choose "put positive first". But
again, that's more a bias than a rule. In particular, it might often be best with an "early exit" coming first regardless of whether it is the positive condition or the negative condition.
But we know better: the one best practice that would be relevant there
is *do not use magic values*.
On Thu, 22 May 2025 11:14:17 +0200, Julio Di Egidio wrote:
But we know better: the one best practice that would be relevant there
is *do not use magic values*.
I think the writer was trying to make a point about
saveUser(user, true, false);
with something more like
I think most of this article is a load of nonsense, myself.
<https://www.infoworld.com/article/3990923/booleans-considered-harmful.html>
Thoughts?
I don't think he's a versatile programmer, if he expect every code to be
self explanatory at any point.
<https://www.infoworld.com/article/3990923/booleans-considered-harmful.html>
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 491 |
Nodes: | 16 (2 / 14) |
Uptime: | 113:55:13 |
Calls: | 9,685 |
Calls today: | 1 |
Files: | 13,725 |
Messages: | 6,176,038 |