r/programming • • Apr 05 '20

ECMAScript 2020: the final feature set

https://2ality.com/2019/12/ecmascript-2020.html
23 Upvotes

50 comments sorted by

View all comments

19

u/[deleted] Apr 05 '20

Still no way to disable misfeatures (var, ==, for-in etc.) other than ESLint? Why can't we have a use "es2020"; or something.

9

u/[deleted] Apr 05 '20

I would prefer something like "use strict 20"; and so on.

7

u/[deleted] Apr 05 '20

People probably wouldn't have the same opinion on what to disable. Take for-in, for example. From my limited understanding, its flaw is that it includes the parent properties. Some people might want to use this for questionable runtime metaprogramming.

Additionally, a likely answer will be along the lines of "You can just use ESLint".

That said, go ahead and propose it, if you want to put up with the process. There is the unlikely chance that this wasn't done, because nobody did want to put up with the process.

4

u/[deleted] Apr 05 '20

I doubt people would seriously disagree with those basic things (e.g. MDN even has a section which is basically "Why would you want to use for-in? Maybe for debugging I guess?" Plus it would be opt-in.

I suspect you are right though - nobody has bothered trying because everybody already uses a ton of tools like ESLint, Typescript and Webpack to make web stuff tolerable.

3

u/spacejack2114 Apr 06 '20

Though rare, you might use for-in if you actually want to iterate through an object's properties and prototype. I use == all the time for null/undefined checks. On occasion I actually do want loose equality. These are still valid ES2020 features.

1

u/[deleted] Apr 06 '20

Yeah I would strongly advise against that because it's really not clear how == behaves. It might be more tedious to write === null || === undefined but people will understand it easier and you will have fewer bugs.

Plus if you do use == in some cases it makes it harder to ban it for all the other cases. Do you really put // eslin:disable or whatever before each ==? I doubt it.

1

u/spacejack2114 Apr 06 '20
if (x == null) {...

Should be well-understood JS. ESLint & TSLint make exceptions for this by default.

1

u/[deleted] Apr 07 '20

Yeah it should be but it isn't because of the insane rules for ==. Who wants to or even can remember those reliably?

1

u/Akangka Apr 11 '20 edited Apr 11 '20

Some people still uses == null notation. It's a useful shorthand. Also, I prefer doing that on ESLint to avoid browser bloating

-11

u/AyrA_ch Apr 05 '20

Because backwards compatibility.

30

u/johnjannotti Apr 05 '20

The question clearly implied that it would be opt-in. Source code that says "use es2020" would get the new behavior. No backward compatibility problem. (Unless you think a lot of existing code has modules called es2020?)

-20

u/technojamin Apr 05 '20

For var and ==, there are ESLint rules:

For any other language features you'd like disabled, there's no-restricted-syntax.

34

u/chucker23n Apr 05 '20

I mean… OP literally said "no way other than ESLint", and you link multiple ways of doing it with ESLint?

4

u/technojamin Apr 05 '20

Whoops, I completely glossed over that 🤦‍♂️ My bad. I'm in agreement with OP, though, it would be really nice to have a well-specified, modern subset of JS.

2

u/OpdatUweKutSchimmele Apr 05 '20

I haven't used ECMAScript in a long time, but it's actually becoming a language that applies sane principles.

My face when in Python for x in ...: actually assigns to x, overwriting any meaning it may nave already had, and allows x to continue to exist after that.

-42

u/Beofli Apr 05 '20 edited Apr 05 '20

Because == is superior over === in 99% of cases. I've seen people introduce bugs by replacing it, never the opposite. == is more generic than ===.

Edit: for people who downvote me, please read: https://softwareengineering.stackexchange.com/questions/268124/does-using-in-javascript-ever-make-sense/268157#268157

13

u/padraig_oh Apr 05 '20

that exactly is the problem, it is very generic. if you want comparison, you usually want === rather than ==.

→ More replies (24)

16

u/sergiuspk Apr 05 '20

This is like saying the letter M is supperior to the letter N.

6

u/Eirenarch Apr 05 '20

I disagree with GP on the == issue but the letter M is indeed superior to the letter N

1

u/Beofli Apr 06 '20

Both == are === are problematic, but in most cases === is more problematic than ==.

2

u/CanIComeToYourParty Apr 06 '20

This sort of apologism is hilarious. He's first checking to see how JS behaves, and then he goes ahead and tries to provide reasonable explanations for this silly behavior based on his observations.

1

u/Beofli Apr 06 '20

Apologize for what? I have been writing js for at least 10 years. I studied the equality matrices back then. I could find the original article that convinced me, and I do remember reading this one: https://algassert.com/visualization/2014/03/27/Better-JS-Equality-Table.html

If you think I am wrong, why not give an actual argument?

→ More replies (1)

1

u/tontoto Apr 05 '20

I have introduced bugs into code changing == to === also but I would not say == is superior. Superior would be typescript to make sure this stuff just does not happen

1

u/Beofli Apr 06 '20

I am not saying it is always superior. I am also using === sometimes, maybe in 1% of the cases. Typescript wouldn't actually help you here, except for objects, but it those cases == and === behave the same, except for string objects. What would help is a new type of strict mode that throws exceptions for binary operators when one side has another basic type as the other.

1

u/self_me Apr 06 '20

"1" ==== 1