Re:Dev Fonts
by rplnt on Friday November 20, 2020 @12:20PM
(#25162577)
Not for comparison, but for boolean checks I prefer to use `foo == false` instead of `!foo`, the latter is easy to overlook.
[ Parent
| on HN ]
Re:Dev Fonts
by franga2000 on Friday November 20, 2020 @02:49PM
(#25164166)
I've recently started using a kind of middle ground by putting spaces around the !. Makes it harder to miss without losing the "reads like text" property that's lost when using == false.
if ( ! isLast(e) ) reads perfectly, especially since my native language doesn't insert the "not" im the middle like english does and my brain is used to that. if (isLast(e) == false) just jolts me out of that state where code reads as fluently as text. YMMV, of course, and I have a suspicion that your native language might play a role in that...
Do all languages have `foo === false`? When testing booleans, I always do the type specific test to avoid `foo = 0 !== false` stuff