4 ms·
Specifically, I would call the haphazard implementation of classes in JS one of these examples of a place where really true OOP should have been added, but they
by sam0x17 4y ago
Specifically, I would call the haphazard implementation of classes in JS one of these examples of a place where really true OOP should have been added, but they couldn't because they had to support existing keywords and web pages and language conventions, so we end up with the hacky syntax that is in the spec today.
Another example is the mess with for each loops, with .forEach, and the for..in syntax, and the peculiar behaviors therein where nothing does what you think it would coming from any other programming language.
Then you have things like "should I use var or let". It's embarrassing frankly. And don't even get me started with the uneven and confusing state of modules across the different ecosystems that exist now.
For someone who has worked in js since the pre ES5 days, it's fine, because we know the history and we know "oh, forEach is a legacy thing, don't use that if you can avoid it" but to newcomers it is extremely overwhelming having this sea of available functions and syntaxes and not knowing what to use. I know because I have had to talk through this with hundreds of coding bootcamp students as I used to serve as a mentor for one of the major ones. I tell all of them that the JS of today is a spaghetti soup of 30 years of tech debt, because it's true.
What's worse, is for newcomers, there is no way of viewing just the new/blessed syntax without going through each ES version and reading through the changes. It is very hard to distinguish the skeletons from the things you should use unless you know the entire history, and that fact is javascript's biggest smell to date. And it's also impossible to explain the new syntax in isolation without a story about what it replaced and why what it replaced fell out of favor.
JS has been adding new language features at an alarming rate, doing so poorly, and the reason for this is they have to walk on eggshells so as not to break existing web pages. Multiply that by 30 years and you get the mess that is everything since the netscape days. Things really got off the rails with ES6+, though, in terms of adding "awesome" new stuff without fixing/reworking old stuff. It's just plastered on in time-sensitive, fragile layers.
- woojoo666 4y agoThat's not the experience I have actually using javascript on a day to day basis. People don't use prototypes anymore, they uses classes. People don't use var anymore, they use const or let. People generally don't use `for...in` or .forEach() anymore, they use `for...of`. The javascript experience is a lot cleaner now, because of all the evolution in the past few years. For those who only code in javascript once every few years it can be jarring, but the ecosystem as a whole moves very fast (new frameworks and runtimes like Svelte or Deno), and that can be a good thing too
- s__s 4y agoJavaScript classes are nothing more than syntactic sugar. It’s still prototype-based inheritance under the hood. Prototypal Inheritance is considered one of JavaScript’s strong points, and many, including myself don’t think the class syntactic sugar that was added has much value. If anything it just confuses new developers. A lot of JavaScripts detractors simply don’t understand the language very well.
- sam0x17 4y agoRight. The whole language is held up by a bunch of "people generally" conventions that are non-obvious and frankly difficult to figure out if you haven't been watching the language for 1+ decades. It simply isn't designed for novices to pick up in 2022, and that's a smell.
- Paddy3118 4y ago"People don't use...". They did and they will and you will have to read and understand and maintain that cruft for years to come.
- jitl 4y agoRust solves this kind of thing using "editions" that ensure some features are available, and disable deprecated features. Perl goes super far in this direction with user-defined pragmas (https://perldoc.perl.org/perlpragma https://perldoc.perl.org/perlpragma). Javascript something like this in `"use strict"`. But the standards bodies have ben against adding more of these, or gating new features behind them. The issue always comes down to, how would you choose what features to eliminate? Some, like `var`, can be turned off, no problem. But others like `.forEach` are more debatable. I like forEach, it doesn't seem like legacy to me to have both functional and imperative loops. Another language that has continuously accreted language changes is C++, and I've really struggled to learn it for that reason. It's so hard to find a "how to do it right" kind of guidepost for C++. Like modern JS, there's so many build systems to pick before you even get started...