News for hackers. Stuff that matters.
Re:JavaScript Equality Minesweeper by keymone on Monday September 17, 2018 @05:54AM (#18004474)
it seems equality operator in javascript is good for nothing but being a source of confusion and a target of jokes.

does it not make sense to just remove it from the language completely? who is deciding that?

Re:JavaScript Equality Minesweeper by Nimelrian on Monday September 17, 2018 @07:32AM (#18004877)
> it seems equality operator in javascript is good for nothing but being a source of confusion and a target of jokes.

  if (someValue != null) {
    // someValue is neither null nor undefined
  }
> does it not make sense to just remove it from the language completely?

No, because you'd wreck quite a bit of the internet with that.

> who is deciding that?

ECMA TC39

Re:JavaScript Equality Minesweeper by alangpierce on Monday September 17, 2018 @11:17AM (#18006719)
> does it not make sense to just remove it from the language completely?

The way syntax is "removed from the language" in JS is by introducing commonly-used lint rules that disallow them, and that has already happened with `==`: https://eslint.org/docs/rules/eqeqeq . As long as the community makes it so a standard project setup has a linter with good defaults, `==` can effectively be removed from JavaScript without having to break nearly every website in existence (which is what would happen if browsers decided to start crashing on `==`).

Re:JavaScript Equality Minesweeper by slikts on Monday September 17, 2018 @06:09AM (#18004545)
You can't remove JavaScript features without breaking websites. The one exception was when the strict mode pragma was added, but that was a one-off, and there's too much resistance now to add more pragmas (they tried that with "strong mode").

The best solution currently is to have linter rules enforcing ===.

Re:JavaScript Equality Minesweeper by simias on Monday September 17, 2018 @09:03AM (#18005505)
I'm actually surprised that it doesn't give you at least a warning when you "use strict;". That being said plenty of JS linters will yell at you if you use '=='.
Re:JavaScript Equality Minesweeper by paradite on Monday September 17, 2018 @07:38AM (#18004908)
> it seems equality operator in javascript is good for nothing but being a source of confusion and a target of jokes.

I would say that's the defining characteristics of JavaScript.

It makes it fun to write JavaScript with its quirkiness and "dynamic" nature. And once you master it you become a ninja.

Compare it to Java or Golang where you are restricted by the language syntax and anything slightly creative and fun is either not supported or not idiomatic.

Re:JavaScript Equality Minesweeper by keymone on Monday September 17, 2018 @07:49AM (#18004956)
> It makes it fun to write JavaScript with its quirkiness and "dynamic" nature.

nope. none of that. there are plenty of fun, dynamic languages that aren't the horrible pile of shit that is raw javascript.

> And once you master it you become a ninja.

wait, was this sarcasm? hard to tell..

Re:JavaScript Equality Minesweeper by simias on Monday September 17, 2018 @09:07AM (#18005539)
You'll have to show me one inventive and useful "ninja" trick revolving around the use of '=='. Sounds to me like the classic "my programming language is perfect and if you don't like it you're just too dumb to get it". This is pretty common among C developers in my experience but I didn't expect that from JS enthusiasts. What's next, PHP ninjas?
Re:JavaScript Equality Minesweeper by thalesmello on Monday September 17, 2018 @02:12PM (#18008388)
> You'll have to show me one inventive and useful "ninja" trick revolving around the use of '=='

Sure! For starters, you can write

    if (foo == null) { ... }
Because `undefined` gets coerced to `null`, it saves you from writing:

    if (foo === null || foo === undefined) { ... }
And, because it's shorter, it's even allowed by [some JS linters](https://standardjs.com/).

There you have your JS ninja trick to handle two distinct null types^TM .

Re:JavaScript Equality Minesweeper by simias on Monday September 17, 2018 @06:38PM (#18010731)
I would argue that it's only a "feature" because JS has this needless dichotomy between null and undefined so it's basically two issues cancelling each-other, but that sounds a lot like moving the goalpost so I'll concede the point.
Re:JavaScript Equality Minesweeper by thalesmello on Monday September 17, 2018 @07:01PM (#18010865)
Just to make sure, my "ninja trick" was meant in an ironic manner. In my opinion, it sucks JavaScript has two equality operators, and it's inexcusable for it to have two different null types. That fact that you can use the forer to check for the latter with less code doesn't make either okay in any sense.
Re:JavaScript Equality Minesweeper by paradite on Monday September 17, 2018 @10:55AM (#18006471)
>You'll have to show me one inventive and useful "ninja" trick revolving around the use of '=='.

1. I was making a generalized statement around JS, not specifically '=='. That's a misinterpretation of my statement.

>"my programming language is perfect"

2. I did not say JavaScript is perfect. That's a misinterpretation of my statement.

>"if you don't like it you're just too dumb to get it"

3. I did not say "if you don't like you're just too dumb." That's a misinterpretation of my statement.

Re:JavaScript Equality Minesweeper by thebuzzsaw on Monday September 17, 2018 @12:43PM (#18007512)
Did you stop to consider that maybe you conveyed these ideas regardless of whether you meant to?

JavaScript really _isn't_ all that expressive.

Re:JavaScript Equality Minesweeper by paradite on Monday September 17, 2018 @01:39PM (#18008056)
I tried my best, but I can't control how other people interpret it. That's what comments are for after all, to deal with information asymmetry like this.

I just don't get it. What's wrong with expressing my love for a language that I love? I am not even asking for anyone to switch to JS, just expressing my feel.

Re:JavaScript Equality Minesweeper by keymone on Monday September 17, 2018 @02:04PM (#18008314)
what's wrong with people disagreeing with you? isn't that what comments are (partly) for?
Re:JavaScript Equality Minesweeper by paradite on Monday September 17, 2018 @02:12PM (#18008393)
Yes. Maybe I am too conscious of people disagreeing with each other. It's actually very normal.

Thanks for pointing that out.

I think might be due to the downvotes somehow. It makes you wonder if you did something wrongly or it is simply people disagreeing with you.

Re:JavaScript Equality Minesweeper by flavio81 on Monday September 17, 2018 @01:17PM (#18007848)
>It makes it fun to write JavaScript with its quirkiness and "dynamic" nature. And once you master it you become a ninja.

Yes, a ninja of the "undefined is not a function" wars.

Re:JavaScript Equality Minesweeper by Sohcahtoa82 on Monday September 17, 2018 @01:23PM (#18007908)
> slightly creative and fun

In my experience, code that is "slightly creative and fun" is unreadable and not actually useful for creating working products as a part of a team.

Re:JavaScript Equality Minesweeper by paradite on Monday September 17, 2018 @01:35PM (#18008028)
Do you mean you prefer to just follow instructions given by product managers as a robot rather than exercising your creativity and enjoy coding? Or am I reading your statement wrongly? That sounds like a terrible job to have.
Re:JavaScript Equality Minesweeper by Sohcahtoa82 on Tuesday September 18, 2018 @03:07PM (#18018185)
I'm interpreting "creative and fun" as either synonymous with "overly clever" (which is hard to read, hard to debug, and hard to maintain [0][1]), or written a non-standard way just for the sake of being different. For example, here's a collection of FizzBuzz solutions[2]. Most of these are incredibly unreadable.

[0]https://www.simplethread.com/dont-be-clever/

[1]http://www.delabs.io/clever-code-is-bad-code/

[2]https://ditam.github.io/posts/fizzbuzz/

Re:JavaScript Equality Minesweeper by matthewmacleod on Monday September 17, 2018 @12:50PM (#18007595)
Honestly… The last thing I want in most of my code is "creativity" and "fun".
Re:JavaScript Equality Minesweeper by paradite on Monday September 17, 2018 @01:36PM (#18008031)
Well then, your life, your choice.
Re:JavaScript Equality Minesweeper by matthewmacleod on Monday September 17, 2018 @04:11PM (#18009571)
Sure, until I end up working on someone else’s codebase, and have to clean up the “fun” and “creative” code they thought would be a better idea than “simple,” “idiomatic,” and “explicit”!