Profile picture
Gary Bernhardt @garybernhardt
, 11 tweets, 2 min read Read on Twitter
I've been writing a lot of JavaScript lately, and I constantly wish that there were an alternative designed by one person, rather than by historical accidents followed by a committee. My kingdom for a Python-like or Ruby-like or even a Perl-like!
One example of many. In Ruby, you can merge hashes (JavaScript "objects") by doing `x.merge(y)`. That's been in forever. It's a simple thing. You call merge; done.
The JS standards body standardized their equivalent syntax (`{...x, ...y}`). It's a nice syntax! Great! But the JavaScript ecosystem is so labyrinthian that tool support, docs, blog posts, are all inconsistent. And all three change monthly, but the old ones remain available.
So in every *other* programming language, we can add a simple function like Ruby's Hash#merge, and it's fine, and no one bats an eye. But in JavaScript, everyone gets ten times as excited, produces 100 times as much writing and discussion... and support for it is unpredictable.
Because Twitter tends to read criticism of anything JS-related as a moral condemnation: this has nothing to do with the people involved. We locked ourselves into a monoculture built on top of a language that wasn't designed. This is about the best we could've expected given that.
It's strange that the accepted solution is "throw another compiler in front of the compiler" in the form of Babel... which itself is a monoculture. Solve the monoculture by layering another monoculture over it. Doesn't seem right.
Another similar example. How do you spell "get the last element of an array"?

Python (as of 1990): xs[-1]
Ruby (as of 1995): xs[-1]

JS (also as of 1995): xs[xs.length - 1]
JS (as of 1999, probably an uncommon idiom): xs.slice(-1)[0]
JS (as of 2015): var [x] = xs.slice(-1)
Every JavaScript version, past and current, is obviously worse than negative indexing, which existed before JavaScript was rushed out the door. (It was rushed out by Netscape as a play to slow the adoption of Sun's Java applets.) Why don't we adopt the 28-year-old simple thing?
This doesn't look like a huge issue when considering single values. But what happens in real life?

Python or Ruby:
g(f()[-1])

JavaScript, 1995:
var xs = f()
var x = xs[xs.length - 1]
g(x)

JavaScript, 1999:
g(f().slice(-1)[0])

JavaScript, 2015:
var [x] = f().slice(-1)
g(x)
I'm reminded by @sgrif that `xs.last` is more idiomatic Ruby than `xs[-1]`. That just raises the further question: why on earth don't JavaScript's arrays have `last()`? You don't even have to invent this stuff, committee folks! Just copy Enumerable!

ruby-doc.org/core-2.5.1/Enu…
(If you actually do this, please make all of them non-destructive. Thank you. Please.)
Missing some Tweet in this thread?
You can try to force a refresh.

Like this thread? Get email updates or save it to PDF!

Subscribe to Gary Bernhardt
Profile picture

Get real-time email alerts when new unrolls are available from this author!

This content may be removed anytime!

Twitter may remove this content at anytime, convert it as a PDF, save and print for later use!

Try unrolling a thread yourself!

how to unroll video

1) Follow Thread Reader App on Twitter so you can easily mention us!

2) Go to a Twitter thread (series of Tweets by the same owner) and mention us with a keyword "unroll" @threadreaderapp unroll

You can practice here first or read more on our help page!

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just three indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member and get exclusive features!

Premium member ($3.00/month or $30.00/year)

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!