News for hackers. Stuff that matters.
Re:JavaScript: The Curious Case of null >= 0 by carapace on Saturday September 09, 2017 @04:50PM (#15209094)
> If he is an authority on the subject, it should show through in his comments.

The comment speculating on the "OTHERWISE" clause is the kind of brilliant off-beat thinking that challenges the level of understanding of the reader.

The people scoffing at and downvoting it are, however smart and knowledgeable they may be, ignorant or foolish. If they thought it through they might learn something.

It's a perfectly valid response to say, "Hey wait a minute, I know what I'm talking about here." It's not appeal to authority, and it is certainly not an ad hominem since the people he's talking to have shown that they don't understand.

Re:JavaScript: The Curious Case of null >= 0 by curun1r on Saturday September 09, 2017 @05:33PM (#15209263)
> brilliant off-beat thinking

Those words must have new meaning since he was citing as an example a language that's existed since the 70s. Ternary booleans are far from a unique or novel concept. The main difference is that for most languages, including Javascript, that third value exists at the variable binding or expression level, not the value level. Other languages that don't allow nulls encode that third value in a Maybe type. SQL, being a thin abstraction over data storage that needs to be able to encode nulls, doesn't make that distinction. That his idea was poorly worded to state that the actual Javascript value would have a third possibility rather than the comparison expression being nullable doesn't add to his credibility. The distinction between an expression evaluation, variable binding and a value isn't exactly a newbie concept, but for someone with the credentials he's claiming, I'd expect him to know it and be more precise.

> since the people he's talking to have shown that they don't understand.

Perhaps you should go back and read the exchange. The comment he was replying to was specifically about the mixture of Javascript and ternary booleans, not just ternary booleans. Also, if you re-read the comment that you're calling ignorant in the context of the authors original confusing of expression evaluations and values there's at least the possibility that he's making a very valid point, albeit in a way that can be read as confrontational. Javascript could already add an otherwise block without adding a third boolean value...all that would be necessary is to allow comparison operators evaluate to null or undefined and then execute the otherwise block in that case. Adding a third value would mean that a boolean variable binding could now have 5 values, true, false, not_true_or_false, null or undefined. That's nonsensical and deserves to be called out. It's bad enough that the language has null and undefined, since it causes a ton of confusion that could have been avoided. Adding some special "not null but sort of null" boolean value would just add more confusion to the language.

Re:JavaScript: The Curious Case of null >= 0 by carapace on Sunday September 10, 2017 @01:55AM (#15210906)
Alright, you got me. I went back and re-read the thread and I misunderstood what lisper was saying. You're right. I thought the OTHERWISE clause would run for null or undefined, but lisper does mention a third Boolean value. Your points above convinced me that that wouldn't work well (at least in Javascript.)

I still disagree about the argument from authority, but I think that's subjective.

Warm regards.

Re:JavaScript: The Curious Case of null >= 0 by lisper on Saturday September 09, 2017 @07:53PM (#15209726)
> Adding a third value would mean that a boolean variable binding could now have 5 values, true, false, not_true_or_false, null or undefined. That's nonsensical and deserves to be called out.

FWIW, I actually agree with this. There's no need to add a new value. It would be fine with me (within the context of Javascript's already horribly broken design) to use an existing value (null or undefined) as the third "boolean" value.

The part that really matters is that whatever null>=0 returns it should be different from either 1>=0 or -1>=0.

Re:JavaScript: The Curious Case of null >= 0 by curun1r on Saturday September 09, 2017 @08:48PM (#15209902)
I think we mostly agree, which is why I upped your original comment calling for an otherwise block, despite the unnecessary (or imprecise) call for a third boolean value. As a slightly more verbose option that didn't involve adding a new 'otherwise' keyword, it could also be implemented with a catch block with the comparison operator throwing an exception rather than silently coercing. I find both an improvement on than the current behavior.

I was merely explaining why I downed your other comment. I don't care if you're a fresh bootcamp grad or the former lead on AdWords...your argument is equally compelling. I'm calling it out because I think it discourages people from engaging in conversations where they can learn. If you are who you say you are and have the experience I think you do and someone significantly more junior disagrees with you, it's an opportunity for you to explain your thinking in a way that helps them improve theirs going forward. Instead, you took an expedient and, IMHO, intellectually lazy route. It's a small thing, but it's all part of making our field more welcoming to newcomers. What JavaScript beginner is going to argue with the ex-AdWords lead? Beyond being an appeal to authority, your comment possibly shut down someone's positive learning experience.

And if it seems like I'm quibbling with you or being overly hard on what you've said, that part is definitely about who you are. I feel like those of us who've been in the industry a while (I'm a few years behind you, but I'm still nearing my 20th year doing this stuff) have an obligation to be better about technical discussions and work towards positive conflict, even if the other side seems intent on going negative. It's hard and I fail at doing it constantly, so I say this with the full realization that I'm often the proverbial 'pot' to your 'kettle'.

Re:JavaScript: The Curious Case of null >= 0 by fenomas on Saturday September 09, 2017 @11:34PM (#15210442)
It seems like this thread has gone several different directions. Surely suggesting that that (null>0) should return null or undefined is a separate topic from suggesting that if() statements have three different control branches?

FWIW, I totally buy the former. If (null>0) returned null, then most things would still work as expected, and you could easily check the result of the comparison to catch unintended behavior. One can easily imagine a world where JS was defined this way from the start, and it'd be pretty much the same language.

The latter (three-way IF control structures) strikes me as waaaay more tenuous - much bigger change, more complexity on the programmer, and no benefits I can see that you wouldn't get from the former bit.

Re:JavaScript: The Curious Case of null >= 0 by lisper on Sunday September 10, 2017 @02:10AM (#15210960)
The reason for the three-way IF would be to avoid conflating null and false. Without that you'd have to write:

    IF (x<y)==null {
      [otherwise]
    } ELSE IF (x<y) {
      [then]
    } ELSE {
      [else]
    }
That seems awkward to me.
Re:JavaScript: The Curious Case of null &gt;= 0 by fenomas on Sunday September 10, 2017 @03:20AM (#15211139)
Yeah, I get that that's the intent, but (per my original comment) I'd think it would surely create more mess than it cleans up.

For example, I suspect that three-way IFs like you describe would only really get used in two ways - often the second and third branches would be identical, and the rest of the time the third branch will be some kind of "console.warn('bad inputs!')" kind of error handling.

For the latter of those two cases, testing for the error case before proceeding to the regular logic (as in your code sample above) seems intuitively like the right thing to do - analogously to how you might check (isNaN(operand)) before doing some math. And in the former case, if the second and third branches are identical you'd almost certainly want some syntactic sugar to avoid writing the same logic twice, like "IF (bool) {...} ELSE-AND-OTHERWISE {...}" -- which would just be isomorphic to what we have now. You know what I mean?