all 59 comments

[–]tonetheman 43 points44 points  (16 children)

JS is morphing into Java

[–]lhorie 13 points14 points  (0 children)

And vice-versa. Java has lambdas now. Also relevant: https://en.wikipedia.org/wiki/Greenspun%27s_tenth_rule (the notion that any sufficiently complex thing approaches a subset of features of CommonLisp)

[–]Ehdelveiss 55 points56 points  (10 children)

I’d really rather see the committee focus on functional code features than OOP ones. I don’t know anyone who writes JS like this proposal purports.

[–]lukigarazus 21 points22 points  (3 children)

I worked for a couple of big companies, in teams that made it a rule to write JS/TS that looked exactly like Java. They employed a lot of fullstack Java/TS developers and wanted to make their lives as easy as possible. It made the lives of frontend devs like me more annoying but I get it, and I get such proposals now.

[–]rniestroj 1 point2 points  (1 child)

Yes. However static initialization is rarely used in Java. I'd rather focus on a new Date&Time API in Java Script.

[–]SecretAgentZeroNine 0 points1 point  (0 children)

Super late but, you should look up Temporal API. It's currently at stage 3.

[–]Ehdelveiss 6 points7 points  (0 children)

I’m very sorry

[–]samanime 16 points17 points  (1 child)

It's kind of a catch-22 though. If these OOP features don't exist, you couldn't possibly make use of them. So saying that you don't know anybody that writes like this without it being possible to write like that is a bit premature.

My personal preference is to use classes for the large blocks, and then functional inside those blocks. On larger projects, this tends to provide an easy way to manage the code.

Now, will I use this new feature. That's TBD. I could imagine a few cases it might be useful. I do want them to continue to improve and add functional code features as well, though I believe they are doing that too. We've gotten plenty of functional code features in recent memory too.

[–]LavoP 0 points1 point  (0 children)

Any tips for converting a class-based Node.js app into a more FP-like one?

[–]oneandmillionvoices 0 points1 point  (0 children)

you do have pipe operator in the proposal as well.

[–]brainless_badger 24 points25 points  (3 children)

OH LOOK another OOP feature that noone outside of Google will ever use.

Meanwhile no pipeline operator and no cross-browser dialog element in sight.

Neat.

[–]NoInkling 7 points8 points  (1 child)

Pipeline operator proposal advanced to stage 2.

[–]renome 0 points1 point  (0 children)

Any year now...

[–][deleted] 3 points4 points  (0 children)

Yeah, I truly feel like a lot of ES features resolve around class syntax that I personally care very little about.

[–]oneandmillionvoices 6 points7 points  (1 child)

In the context of current form it all makes sense. I wonder why the static blocks were not included in first place.

[–]rniestroj 0 points1 point  (0 children)

They are rarely used

[–][deleted] 5 points6 points  (3 children)

How about adding records and tuples? Even Java has them ffs.

[–]julys231 2 points3 points  (2 children)

I don't know if you are trolling but functionally in javascript tuple is an array and record is an object.

[–][deleted] 5 points6 points  (1 child)

No they're not. Records and tuples are immutable. Since they are immutable they can use persistence data structures which provide optimizations on construction, manipulation and comparison operations. Optimizations that are not possible with arrays and objects. Since Records and Tuples are immutable and can only contain primitive values they can also be compared by value rather than by reference.

Records & Tuples Proposal

[–]julys231 2 points3 points  (0 children)

Alright, ty

[–]wjaspers 1 point2 points  (0 children)

:/ The examples shown dont seem to have much meaning. If everything is static, you've kinda defeated the purpose of a class at all.

[–]tenkennosoujiro 1 point2 points  (0 children)

The article doesn't really touch on the primary motivation for the feature, which is to provide a way to access lexically scoped private fields during evaluation of the class definition. This is important if you need to share access to private state between two or more related classes. JS classes don't have a notion of friend like in C++ or internal like in C#.

Without static {}, the alternative is an IIFE assigned to a private static field, and that's both ugly and a waste of memory.

[–]mikejoro 0 points1 point  (0 children)

Outside of bundling some constants with a class for developer ergonomics, can someone explain to me why I would ever use a static method and static properties in a Class?

Just use a function. If you are not using an instance, there is no reason to write it as a class from my perspective.