4 ms·
Personally, my eyes and brain just can't scan ligatures in code efficiently, I have to double read the code, especially "is that =, ==, or ===? Oh, and that's
by DrBazza 6y ago
Personally, my eyes and brain just can't scan ligatures in code efficiently, I have to double read the code, especially "is that =, ==, or ===? Oh, and that's !=="
(edit) I'll additionally qualify my comment, from a mathematics background I can casually scan a handwritten "!=" which is the same as the ligature, but I just cannot retrain my adult brain to accept the ligature version which is the same as the handwritten one. Brain plasticity I suppose.
- LandR 6y agoI find some ligatures help a lot. I can often miss != but won't miss ≠ or ≢ I think the whole idea of pre-pending ! to negate is a poor idea in general, it's too hard to spot especially in long convoluted lines where it's just thrown in before a complex bracketed expression.
- Lukas_Skywalker 6y agoI sometimes use a triple negation !!! for that reason. I don‘t know if there are any drawbacks, especially if there are other people working on the code, but it worked pretty well for me so far.
- pvorb 6y agoThat might work until there's somebody who uses double negation !! for some reason. But this might only be common in JavaScript, so YMMV.
- LandR 6y agoI had to google this to see why on earth you would use double negation. Apparently it's a way to negate and convert to boolean.
- franga2000 6y agoYes, it's one of those dirty JavaScript tricks that abuse type conversion. Negation converts anything into a boolean, so if you negate that again, you get the equivalent of converting the into a bool. In standard (old) JS fashion, it's both slower and less readable, but people still (used to?) do it. Similar hacks include 1* for num->string and +"" for the opposite, along with several others that I have luckily managed to forget.
- FabHK 6y agoI've never had to use JavaScript, but I've done the *1 or &"" in Excel to force conversion to the desired type... yes, let's mercifully lay the veil of forgetting over this.
- franga2000 6y agoConsidering Excel's offical way of writing a != b is a<>b, I think these kinds of hacks there can be excused :)
- uncanneyvalley 6y agoa<>b is the preferred syntax in SQL. I'm pretty sure a!=b works everywhere these days, but that hasn't always been the case. (eta: didn't finish the thought - I'd assume SQL influenced Excel, since it's older.)
- pvorb 6y agoAs I'm not keeping up with recent progress of the language, how would you do that today?
- czynskee 6y agoIf x is your variable, you can just do Boolean(x) rather than !! to make it boolean. E.g. it will convert undefined, null, 0, "", and NaN to false. This is a much more readable cast.
- DrBazza 6y agoEven looking at what you've typed was hard for my old (!!) brain to read, especially != and !==. It's brain training - you find "!" hard to spot, and I don't. And vice versa for ligatures. Thank goodness we both have choices!
- rplnt 6y agoNot for comparison, but for boolean checks I prefer to use `foo == false` instead of `!foo`, the latter is easy to overlook.
- franga2000 6y agoI'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...
- dylan604 6y agoDo all languages have `foo === false`? When testing booleans, I always do the type specific test to avoid `foo = 0 !== false` stuff
- Jenz 6y ago> Do all languages have ... Of course not
- camgunz 6y agoSeconded. I get it for math but, it's just super confusing in code. Like, most of us agree "there should be one obvious way to do it" in code. Why don't we think the same about what code looks like? That feels much more fundamental. Obligatory digraphs/trigraphs reference: https://en.wikipedia.org/wiki/Digraphs_and_trigraphs#C https://en.wikipedia.org/wiki/Digraphs_and_trigraphs#C