Deutsch English Français Italiano |
<100n64t$32ghp$2@dont-email.me> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail From: Julio Di Egidio <julio@diegidio.name> Newsgroups: comp.programming Subject: =?UTF-8?Q?Re=3A_=E2=80=9CBooleans_Considered_Harmful=E2=80=9D?= Date: Thu, 22 May 2025 14:43:08 +0200 Organization: A noiseless patient Spider Lines: 43 Message-ID: <100n64t$32ghp$2@dont-email.me> References: <100mhh5$3b9hp$3@dont-email.me> <100n34e$3eqip$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Thu, 22 May 2025 14:43:09 +0200 (CEST) Injection-Info: dont-email.me; posting-host="982abdda2b1bb3b14ada760c28c7713c"; logging-data="3228217"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/GJJwrJtR0BPdFppL2lTiwLWjak6D9xfc=" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:8iPFcstT91T48w+95gMHBveMSTw= In-Reply-To: <100n34e$3eqip$1@dont-email.me> Content-Language: en-GB, it Bytes: 2863 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. -Julio