"What do you think of JavaScript"? πŸ‘Ύ

Friday, May 18, 2018 :: Tagged under: engineering. ⏰ 7 minutes.


Hey! Thanks for reading! Just a reminder that I wrote this some years ago, and may have much more complicated feelings about this topic than I did when I wrote it. Happy to elaborate, feel free to reach out to me! πŸ˜„


🎡 The song for this post is Bustin', by Neil Cicierega. 🎡

I shared this talk with a friend of mine who's hoping to make biggers waves in computing, and he asked me "what do you think of JavaScript?"

I believe JavaScript exceeds all other languages in its ability to generate unproductive conversations; the thought of answering this gives me the willies. I'm half-tempted to pull a Kevin Williamson and just never articulate a clear position to a simple question, sputtering angrily and huffing if anyone tries to infer meaning from what I say. But that's no fun, I'll try to answer the question as best as I can.

The short answer is I don't usually love it; but have loved it before and most haters are shortsighted. Let's elaborate, I'll start with the flames, since that's probably what you're here for.🍿

Goodness, JavaScript Was Bad

There are four meanings of this. var scoping and function hoisting have no precedent in any other language I can find (it's usually just called a scoping bug). Before strict mode, if you define a variable without var it is globally scoped by default. All functions are vararg functions. You have no integers, all numbers are floats. Null, the billion-dollar mistake, is in JavaScript, but there's another value that means nothing, undefined. Implicit casting rules, combined with truthy/falsey values, are a legendary hell. ==, but also ===!

And listen: there's a lot of undue hate to JavaScript and its community. But even if it's a language you use and love, I can never look at the above and think "wow, this language is Actually Good. No language intentionally has such an abundance of pitfalls and loose correctness criteria; these things do bite people, cause bugs, hurt products, and are generally a part of all things any reasonable person calls "bad software."

This isn't to say it's not liveable (we clearly do live with it), but I don't think I can ever love this language when there's all this mess going on.

But it was designed in 10 days!

True! But if I cook a turkey in the oven for half the time, I'm still asking you to eat a frozen turkey. JavaScript-by-default is a frozen turkey.

But [thing you mentioned] isn't a problem anymore because [subsequent library or tool]!

Through strict mode, subsequent ECMAScript revisions, and tools like Babel, it's entirely possible to write many variations of JavaScript, including adding checks to ensure you're writing whichever subset you like.

JS vs JS The Good Parts. Click for full size.

an old meme

There's an old joke about Domain-Specific Languages: it's where you program the app in one language but debug it in another. Even if you have the opportunity to use fancy whiz-bang Modern JavaScript, you can't get away without knowing the 10-days subset.

Many companies you'll work at are still using Backbone or Angular 1 or whatever tool was popular at the time. You may be maintaining CoffeeScript v1! Which was great, but it's also an uncanny valley of "kinda ES6 but not."

In this way, you still have to know all the pitfalls of the language to appropriately maintain and debug, since many codebases won't (for reasons of history or portability) get to take advantage of The New Hotness.

I'll also note that there's setup cost to incorporating all these tools. Ever seen a Gruntfile with all the bells and whistles attached? Or were you one of the cool kids to move to a webpack file? Or are you the new school using Makefiles? The tools may work well together or they may not, but it's always been non-trivial effort for me to get the perfect JavaScript project set up.

And the [subsequent library or tool] you mentioned? There's usually competition behind which one to use, and it's normally to add some language feature that exists elsewhere. Did you pick TypeScript or Flow? Cool, you just got types. Remember when we were fighting over RequireJS and CommonJS? Nice, now you've got modules, until ES6 got modules (in their defense, C++ still doesn't have them 😝).

Having to choose between popular competitors and configuring it into a working build system goes beyond language features: did you pick Bluebird or q for promises? Ever seen a project with both .jshintrc and .jslintrc? Are you into Chai or Jasmine? Did you get on the Bower train when that was the way to build things? Did you/do you invest in Brunch? Browserify? Yeoman? Yarn or NPM? And on and on and on… these are all off the top of my head, and I've never been a full-time frontend dev!

To be clear, ecosystem competition is great, and I love most of these tools. But almost all of those tools are, in my mind, addressing weaknesses in the language and/or building projects in it, and there is a lot of mental overhead in keeping track of any of them.

Man, Hating JavaScript is Boring and Tired

At the same time, server developers like me have a terrible habit of being self-serious and treating their programming like it's Real Programming. The browser is a fucking nightmare, and developers who build tools and program for it deserve massive commends.

It's also worth noting that other languages aren't really aren't much better at this. It's hard to complain about build tools when you consider what goes on in a ./configure script, or think about trying to produce a project in Python:

It's worth mentioning that a lot of JS's complexity comes from serving the most globbed-on, fast-changing, widest-available platform and APIs in history. JS applications have to make sense of a document model that does multiple network calls compatible with every possible display size. Of course its got messy bits.

Lastly, JavaScript and its ecosystem has been a boon for bringing new developers into the industry. I'll take a language with twice as many warts if it could bring so many wonderful, enthusiastic, brilliant people to modern spellcasting πŸ§™πŸΌβ€β™‚οΈ

What I love about JavaScript

There's one thing I absolutely, positively love about JavaScript that virtually no other mainstream language has: transparent object types. You can take any object, pass it to console.log(JSON.stringify(obj)); and inspect its properties.

In Java you have to you write toString(), Python it's __str__(), Ruby it's to_s, and in each you have to keep it up to date with its fields. And you can only really do this with objects you define!

While it's dogma that objects should be opaque and we should operate purely on interfaces, in practice, when I need to see what's happening, I find this invaluable. I'm a printf debugger through and through.

Similarly, the Chrome and Firefox teams have made extraordinary investments in developer tools, which make debugging a lot of the hells of CSS and JavaScript downright fun.

The giant, giant community has produced reams of useful, widely-accessible code. If someone hasn't written a JavaScript module, you're doing something really obscure.

More reading

My favorite JavaScript books are Effective JavaScript by Dave Herman, and JS books written by Reginald Braithwaite.

I love the web and am glad its winning; the web as a terrible, horrible, very bad, no-good platform that probably shouldn't have so much power in execution context is well-illustrated by this tale.

If I could be said to have a JavaScript aesthetic, it's this, on writing as little as possible. It links to this article, which I also liked. On the whole, you can avoid a lot of problems with JS if you merely choose not to use it. Sticking with HTML + CSS, you get the following for free:

Similarly, I like the Vanilla JS splash page πŸ˜›

Related questions I'm not tackling in-depth β€” rapid fire!

Common uses of JavaScript? β€” adtech is spyware and is ruining society.

How do you feel about The Most Modern Version of JS? β€” it's far too much like Scala, doing too many things at a time, gives me a headache to read it.

Subjective gripes or praises do you with JavaScript implementations? β€” cooperative scheduling (vs. preemptive scheduling) is silly in a language with so much async; ditto Node only running on one core.

Surprise me β€” I use JavaScript in programming interviews; I've internalized its pitfalls better than Ruby or Python, and since I'm usually doing a rapid-debug cycle the transparent objects and objects-are-hashes are super helpful to me.


I promise I'll blog something unambiguously positive next πŸ˜„

Thanks for the read! Disagreed? Violent agreement!? Feel free to join my mailing list, drop me a line at , or leave a comment below! I'd love to hear from you πŸ˜„