Javascript is here to stay

Like it or not, Javascript is going to be around for a while.

This article is not, in and of itself, particularly relevant to language documentation, as it deals with (a cool) programming language called Haskell. Haskell has the reputation of being a very cutting-edge, even difficult language.

I’ll be perfectly honest, I have no idea what most of the article is about! :thinking: Apparently the creators of the Glasgow Haskell Compiler are working on making their tool output Javascript. If I understand correctly, the idea is your write some Haskell, and the compiler outputs Javascript, which can then run, I presume, in web browsers.

There’s just one paragraph I’d like to draw your attention to (emphasis added):

To put it simply, the number of users on the internet is as low as it will ever be right now, and it is almost guaranteed that those users use JavaScript. At time of writing, JavaScript holds 97.3% of client-side programming market share (not to mention market share of front-end technologies). Furthermore, JavaScript is not going to disappear anytime soon. As more and more interactivity is pushed onto the internet, JavaScript will become more entrenched because of backwards compatibility, network effects and the amount of capital already devoted to it. JavaScript, like C and COBOL will be with us for the foreseeable future. This makes JavaScript an attractive target; it provides portability, allows us to capitalize on the massive investments in the language and platform, and essentially eliminates the risk that the we build our technology atop a disappearing or deprecating foundation.

In my opinion we should be making the same bet in language documentation. This is not to say that other programming languages — especially, for our community, R and python — should be ignored, far from it. But Javascript has a uniquely ubiquitous status in the programming landscape.

When the authors talk about “the massive investments in the language and platform,” the thing that stands out to me is the Document Object Model or DOM. This is the thing that makes HTML documents programmable. Because Javascript creates a DOM from HTML, you can write programs that make the page interactive. This is not necessarily obvious to users, who may not have any reason to stop and think about “where” programs are running. What’s revolutionary about Javascript is that it is used in an ecosystem where programs stored just like documents on a server, and then run in the client’s web browser.

This is a super weird idea, when you stop to think about it: web pages have URLs, after all, and look like the they are “on” the server. But the code that makes a document interactive — that is, that turns it into something more like an application than a document — can run on your computer.

There are limits to this approach: a laptop is not a heavy-duty server with massive memory and disk space. So you wouldn’t want to try to distribute a massive database plus a program for accessing it directly to users’ browsers. But what I find interesting is that the definition of massive has been changing. It’s absolutely feasible to run medium-sized databases and accompanying code in this way. And in the early stages of language documentation of an undocumented or underdocumented language, every database is (by definition!) not massive. I believe we should keep exploring this programming environment in language documentation, it’s getting more powerful every day, not less powerful.

2 Likes

That’s right, a bunch of PLs also support this including Scala, OCaml, ReScript, and Clojure. You’ll notice a theme, which is that a lot of these languages with JS compiler backends (aside from Clojure and a couple others) have very advanced type systems compared to JS or TS. People who love type systems are reluctant to do without them, which I think is what explains why it’s mostly these languages which have high-quality JS compilers: they can keep their type system and still benefit from JS as a platform and ecosystem.

Having used Clojure’s JS compiler (ClojureScript), I have to say I’m a huge fan. For various reasons, sometimes you want to be producing JS without writing it directly, and the ClojureScript compiler, at least, is powerful enough that you don’t incur a terribly large cost for not writing native JS.

1 Like

This whole space of Javascript (and WASM) as compilation target is getting pretty wacky:

I guess Atwood’s Law might be due for an update: anything that can be written in any language will eventually be compiled to Javascript.

It would be pretty hilarious if someone figured out how to run FLEx in the browser before it ever runs natively on a Mac! :sweat_smile: