News for hackers. Stuff that matters.
Re:Dev Fonts by DrBazza on Friday November 20, 2020 @07:24AM (#25159764)
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.

Re:Dev Fonts by camgunz on Friday November 20, 2020 @02:42PM (#25164072)
Seconded. 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

Re:Dev Fonts by LandR on Friday November 20, 2020 @09:52AM (#25160939)
I 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.

Re:Dev Fonts by DrBazza on Friday November 20, 2020 @11:00AM (#25161647)
Even 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!

Re:Dev Fonts by Lukas_Skywalker on Friday November 20, 2020 @10:42AM (#25161486)
I 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.
Re:Dev Fonts by pvorb on Friday November 20, 2020 @12:05PM (#25162401)
That might work until there's somebody who uses double negation !! for some reason. But this might only be common in JavaScript, so YMMV.
Re:Dev Fonts by LandR on Friday November 20, 2020 @01:24PM (#25163269)
I 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.

Re:Dev Fonts by franga2000 on Friday November 20, 2020 @02:38PM (#25164033)
Yes, 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.
Re:Dev Fonts by FabHK on Friday November 20, 2020 @02:59PM (#25164287)
I'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.
Re:Dev Fonts by franga2000 on Friday November 20, 2020 @03:06PM (#25164370)
Considering Excel's offical way of writing a != b is a<>b, I think these kinds of hacks there can be excused :)
Re:Dev Fonts by uncanneyvalley on Friday November 20, 2020 @09:02PM (#25167315)
a<>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.)

Re:Dev Fonts by pvorb on Friday November 20, 2020 @07:05PM (#25166656)
As I'm not keeping up with recent progress of the language, how would you do that today?
Re:Dev Fonts by czynskee on Friday November 20, 2020 @08:24PM (#25167114)
If 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.

Re:Dev Fonts by robocat on Sunday November 22, 2020 @03:35AM (#25175938)
Personally I think it is a good rule to never use Boolean(x), String(x), etc.

The problem is that many developers are unaware that `const s = new String(x);` creates a string Object. It looks like a string, and acts like a string, except that in some places it is not a string: for example `typeof s` returns “object”! Same problem for Boolean, Number, etcetera. Yes casts are ok, but it is easier to just say never use the value object keywords because you can end up with very wierd bugs a long way from where the value object was created.

Another example:

    let x = new Boolean(true);
    console.log(x === true);
Gives false.
Re:Dev Fonts by pvorb on Saturday November 21, 2020 @03:02AM (#25168432)
Okay, thanks. And why would it be faster? Optimizing !! in the JS engine seems trivial to me.
Re:Dev Fonts by franga2000 on Saturday November 21, 2020 @03:21AM (#25168479)
I suppose it would be easy and might already be in some engines, but it's still discouraged because you can't rely on that optimisation (there are many engines), it's semantically incorrect, and most importantly much less readable - especially for someone not tok familiar with the JS type system.
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.
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...

Re:Dev Fonts by dylan604 on Friday November 20, 2020 @02:33PM (#25163981)
Do all languages have `foo === false`? When testing booleans, I always do the type specific test to avoid `foo = 0 !== false` stuff
Re:Dev Fonts by Jenz on Friday November 20, 2020 @07:31PM (#25166804)
> Do all languages have ...

Of course not