Hacker News new | ask | show | jobs
by eyelidlessness 3561 days ago
I used to write JS almost exclusively. I can tell you why I dislike it (but I cannot speak for others).

1. It almost could have been. By this, I mean: JavaScript inherited a lot from functional programming. It's impossible to know how much of that was sacrificed in its original design, but its final design (curly braces and dots) is not just a syntactic nightmare, it's downright hostile to JS's functional roots. (See recent posts about whether a given JS function is "pure". Those are perfectly innocent functions, but you cannot provide any guarantees about whether a JS function mutates state.)

2. It's not just dynamically typed. It's impossibly typed. There are code golf games going around ("return true to win") which demonstrate just how esoteric its type system is. One of the reasons (though not often talked about) that the Node ecosystem is so full of hilarious micro-libraries is because you genuinely cannot write a general purpose library of any larger scope in JavaScript that's provably correct. There are too many sources of bad inputs, and too many ways for those to compound, to know that you've written software that does what it says it does under every circumstance.

Let's be clear. Every dynamic language has problems. I can construct comical failures in Python (a language I don't even know that well!). But that leads us to...

3. It is impossible to avoid the hackery of the JavaScript ecosystems. Because the browser environment is broken, and because Node is so low-level, and because the JS universe is relatively welcoming in so many ways to people who don't know they're reinventing the wheel. It's astonishing that the Promise pattern took so long to solidify. It's not really astonishing that sugar around it (async/await) is being designed in completely pathological ways (top-level await).

4. Some of ES6/ES7/ESnext/what is it even called now? is just provably wrong. Do not introduce language features that do misleading things! The `let` keyword denotes immutability everywhere else. Not only does JS violate this, but it has no other immutability story. Arrow functions are not just a simpler syntax for functions, they require developers to know two very complicated sets of rules for `this`!

Side-note: I also used to write PHP full time. JS is doing all the things PHP was doing when I was lucky enough to bail: cargo culting weird stuff that doesn't even make sense. For PHP, it was "how can we Java this up without even approaching Java's performance, breadth of application, or even its data structures?" For JavaScript, it's... decorators? Really? Because JS needs more indirection?

5. Even JS devs don't write JS anymore. You gotta know at least one transpiler and at least one package manager. Good luck if you want to work on another project, even at the same company. Good luck if you want to use a canonical module system. Good luck if you want to know what `import` even means (there's a config file somewhere that says what happens if you import a CSS file).

6. But seriously. Types. Immutability. It's not even addressing these things. When it tries, it's making them comically difficult. `Object.create`, `Object.defineProperty`. Why make it as hard as possible to see what a thing is and how it behaves? How many layers of indirection do we need?

And another redundant side-note: try asking a JS dev in a code review to define an obvious type with a constructor function. They'll look at you like you're crazy. It's idiomatic to just attach random ad hoc properties to some anonymous object to infer what the thing is. What happens when you want to compose them? SHRUG.

- - -

It's not like JS is the worst language I've ever written (that would definitely be PHP, thankfully I never wrote VB or ColdFusion). I'm sorry if I've insulted anyone ranting about this, I really don't mean to. You gotta live with the ecosystem you're in.

I am not super fond of the languages I work in, either. Python has a whole lot of the same root problems underlying the stuff I talked about above. Clojure(Script) has most of its immutability story straight, but basically nothing else. (Well. It's got syntax going for it.)

But yeah. JS has problems. They're probably not fixable. That's why everyone (even JS devs!) is compiling applications of any serious complexity to it.