Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.programming > #16776
| Path | csiph.com!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | David Brown <david.brown@hesbynett.no> |
| Newsgroups | comp.programming |
| Subject | Re: “Booleans Considered Harmful” |
| Date | Thu, 22 May 2025 13:51:41 +0200 |
| Organization | A noiseless patient Spider |
| Lines | 35 |
| Message-ID | <100n34e$3eqip$1@dont-email.me> (permalink) |
| References | <100mhh5$3b9hp$3@dont-email.me> |
| MIME-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8; format=flowed |
| Content-Transfer-Encoding | 7bit |
| Injection-Date | Thu, 22 May 2025 13:51:43 +0200 (CEST) |
| Injection-Info | dont-email.me; posting-host="303de75272ff24d382611025af9d8dc5"; logging-data="3631705"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+tGryEH8FPpT3/Bz0+E9uC1YjHKlWjtMo=" |
| User-Agent | Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 |
| Cancel-Lock | sha1:d0DunmE0dcBVbPsizgEadAUFVrA= |
| In-Reply-To | <100mhh5$3b9hp$3@dont-email.me> |
| Content-Language | en-GB |
| Xref | csiph.com comp.programming:16776 |
Show key headers only | View raw
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, but most is general and unrelated to booleans, and a lot of what he writes is exaggerated. 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. And while I agree with the principle of "no complex expressions", I think he is exaggerating what makes an expression complex, and picking a poor way to handle it. Some parentheses can make a huge difference to readability without needing to introduce extra names. Sometimes nested if's are a good way to split complicated conditionals. Adding extra names is a good idea only if they add clarity to the code - the writer's examples do not. And yes, people /will/ complain about absurdly long variable names. Excessive boolean parameters in functions are bad - but so are excessive parameters of any other type.
Back to comp.programming | Previous | Next — Previous in thread | Next in thread | Find similar
“Booleans Considered Harmful” Lawrence D'Oliveiro <ldo@nz.invalid> - 2025-05-22 06:51 +0000
Re: “Booleans Considered Harmful” Julio Di Egidio <julio@diegidio.name> - 2025-05-22 11:14 +0200
Re: “Booleans Considered Harmful” Julio Di Egidio <julio@diegidio.name> - 2025-05-22 12:04 +0200
Re: “Booleans Considered Harmful” Lawrence D'Oliveiro <ldo@nz.invalid> - 2025-05-22 22:33 +0000
Re: “Booleans Considered Harmful” Julio Di Egidio <julio@diegidio.name> - 2025-05-23 07:04 +0200
Re: “Booleans Considered Harmful” David Brown <david.brown@hesbynett.no> - 2025-05-22 13:51 +0200
Re: “Booleans Considered Harmful” Julio Di Egidio <julio@diegidio.name> - 2025-05-22 14:43 +0200
Re: “Booleans Considered Harmful” Julio Di Egidio <julio@diegidio.name> - 2025-05-22 14:57 +0200
Re: “Booleans Considered Harmful” Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2025-05-22 12:27 -0700
Re: “Booleans Considered Harmful” JJ <jj4public@outlook.com> - 2025-05-23 16:56 +0700
Re: “Booleans Considered Harmful” Lawrence D'Oliveiro <ldo@nz.invalid> - 2025-05-23 22:58 +0000
Re: “Booleans Considered Harmful” Lawrence D'Oliveiro <ldo@nz.invalid> - 2025-05-23 22:48 +0000
Re: “Booleans Considered Harmful” c186282 <c186282@nnada.net> - 2025-06-18 02:40 -0400
csiph-web