I've been learning javascript recently and, considering its reputation, it doesn't seem all that bad?

I mean, it's much more ridiculous than you might think from https://www.destroyallsoftware.com/talks/wat but, compared to other things I've used professionally (Verilog, microcode, C++, Scala, etc.), it doesn't seem bad with respect to the combination of safety, sharp edges, and performance.

Microcode has fundamentally decent reasons for having a lot of sharp edges, so I'll give that a pass, but,

Wat

with respect to sharp edges, I think js is at least vaguely comparable to C++, Verilog, and Scala and I'd actually rate js as much nicer than Verilog and moderately nicer than C++.

In terms of performance predictability, js seems to be in the same league as Scala (actually better IMO) and one big win is that people's mental models seem closer to reality, e.g., I've seen a lot of Scala people say that Scala has Java-like performance if you avoid immutable data structures, which is very wrong.

Python and Ruby are arguably better points of comparison, but js totally blows them out of the water on performance unless you do really funky stuff on the Python/Ruby side.

In that space, Perl is probably the most widely used thing with performance that's vaguely comparable to js, but Perl is also full of sharp edges. I haven't used Perl seriously since 2010 or so, so I can't compare modern Perl to modern js, but I think it would be surprising if modern Perl was leagues ahead of modern js.

@danluu TypeScript (which desugars to normal JavaScript) is tolerable for me as someone who occasionally is forced to do random JS/TS stuff but the fact that the IDE experience with VS Code is so good nowadays is what puts it over the edge.
@danluu
Perl always rocks
-foo
@danluu it’s not leagues ahead, it’s not as far behind as most people think either. JS has had several very large companies pour money into it … ES6 is really fun to write as is TypeScript
@danluu It drives me crazy that Python spent a decade-plus solving no problem that anyone particularly cared about in the 2->3 transition, while multiple F50 companies kept turning out javascript runtimes each faster than the next. Why, as an industry, did we do this to ourselves?
@danluu JS is also evolving fairly rapidly as languages go, but in kind of a unique way because it can't ever make changes that break existing code, and all the stakeholders are being generally sensible about discussing and trying things before making a change "official"
@danluu What makes you feel Perl performance is better than other interpreted langs / vaguely closer to JS? I always enjoy your posting but I do think this point is factually wrong.

@cdleary Hmm, maybe this changed in the past, uhhh, 15 years? I remember benchmarking some basic stuff a long time ago (just boring scripting stuff, not "real" apps or computation) and Ruby and Python were both much slower than Perl.

https://benchmarksgame-team.pages.debian.net/benchmarksgame/fastest/perl-python3.html seems to indicate perl isn't way faster anymore, although I looked at some of the source and it's fairly unidiomatic in both cases, so it's not really what I'd want to see.

Maybe I should replace perl with PHP in the "tweet"?

Perl vs Python 3 - Which programs are fastest?

Perl Python 3 - Which programs have fastest performance?

@danluu @cdleary IIRC the places Perl was fast as a language weren't "fast interpreter", they were "special case in language that gets to mostly stay in C macro-op". Which is a completely viable way to make a fast scripting language! Entirely the point of the Ousterhout dichotomy.

(As my old boss once said "The fastest Lisp is always just the one with the largest set of primitives in its C runtime".)

@graydon @danluu Yeah, I'd find that qualifier technically fair, but also I think would be good to have some key samples in mind to cite. I think a lot of it does come down to the social construct of "would you use e.g. PyPy". One of the funny things about e.g. Python is a lot of usefulness is derived from the ecosystem, as dependent on its C extensions (e.g. numpy, scipy, matplotlib), which can be particularly wed to the CPython implementation. It's a little unfair to race a best-in-class JIT vs an interpreter (Perl or any other) -- they should not generally have similar performance on normal scalar programs, stuff like "whose metaobject protocol is simpler?!" seems likely in the noise at that level. Classic "performance of a language" vs "performance of a particular ecosystem" caveat emptor stuff applies heavily.

@danluu JS is not actually horrible. I like the object model, for instance. I come from a numerical computing perspective and JS really is pretty bad.

JS speed does show what you can do with a dynamic scripting language if several of the largest companies on earth spend a decade throwing piles of money on making it faster.

I can only imagine what Ruby could have been with he same level of interest and support.

@danluu I think most of the perception around JS doesn't stem from the language/runtime itself, but the code it tends to create. Like Wat showed, it has some absolutely head-scratching behaviors which lead to code that's really hard to pick apart after writing, especially if you didn't write it. It's kind of the same reputational problem that PHP or Perl has/had.
@danluu "moderately nicer than C++" is a very low bar. 😉

@danluu I quite like Javascript but I find the community *really* challenging to navigate. I often have a really hard time figuring out what the "standard" pattern for a particular problem is, and when there is one it's often very much not what I'd choose myself (especially re: testing).

Coming from Ruby, Elixir, and Go, I feel like I spend a lot more time trying to figure stuff out and exercising technical judgement about tools. Vs. just picking the "normal" thing and getting to work.

@danluu Like, Jest for instance appears to be the very standard test framework and it takes something like 10 seconds just to run *itself* not even counting actually running tests.

And don't even get me started on package management.

@nat @danluu I think the problem is that there are multiple right answers and everything moves extremely quickly. Assume that for a particular front end project you will pick a reactive framework of some sort, build tools that support it, data / state management (or homegrown), and a CSS / component library (or homegrown). All of these will live with that project forever, but the next thing you start will probably be different.

@danluu I've not done anything actually big with it, but lots of small-ish but not completely trivial things over the years (several things in the ballpark 1-2k LOC outside of libs, so a decent amount of "business logic", not just wiring up one-liners to event handlers).

So far, it's been fine. Definitely a lot nicer and more predictable than most of its contemporary dynamically typed scripting languages.

@danluu It feels less uniform and expressive than Python (which was around in '95, but not nearly as important as it is now) and I'll definitely take it over PHP and Perl, both of which I've written a fair amount of code in and did not particularly enjoy.
@danluu I enjoy JavaScript the language, and even JavaScript the ecosystem to some extent, but JavaScript the build system is something I’d rather avoid.
@danluu I remain of the belief that Apple's Swift started out as a JavaScript compiler that they wanted to have ObjC compatibility.

@danluu You’re doing server-side JS? Node? I would love to get your opinion on React but that’s probably not where you’re going.

As for modern Perl, it’s kind of weird. Perl 5 keeps plugging away, quietly running the world behind the scenes. Perl 6 got so ambitious it stopped pretending to be a new version of Perl completely.

@danluu I agree, it's not that bad. Often people complain that JS is crazy and then the complaint is just IEEE 754 behavior that works as it should in a sensible language.
@danluu I’ve always found JS to be a really pleasant language core that then had a collection of bonkers decisions layered on top of it. The last 10 years or so has had a lot of work in trying to fix or obsolete those bonkers decisions, and what we have today is quite pleasant to work with.
@danluu Lua? It typically outperforms JavaScript (assuming Mike Pall is on his game) and as a language has much fewer warts.

@danluu Yeah, JS is rather reasonable as a language. I think a lot of the hate comes from the perceived junior-ness of the community, as well as the large amount of churn that JS libraries have. But, to be honest, the JS community has done pretty well solving a lot of the problems they have, especially given the popularity of the language (which is probably another factor in why people complain about it).

A large portion of the JS community acts in reaction to not wanting to deal with the DOM apis, though, and I get that.

@danluu When I started looking for programming languages to learn after my first one, all the forums hated on Javascript. Fast forward like 5 years, I was using js (technically ts) at an internship, and learned to really appreciate how productive you can be with it compared to other languages.