One Language to Rule Them All (Not Really)

To a man with a hammer, everything looks like a nail. To a JS programmer, everything looks like a web page.

JavaScript developers never cease to amaze me. In a bad way.

Take mermaid. Mermaid is awesome. If you need to build a simple editable diagram, there’s hardly a better tool. Yes, it’s immensely more limited than PGF/TikZ, it will never get you as far as a graphical SVG editor, but it’s quite enough for the vast majority of the cases and it’s so simple there’s not a learning curve to speak of. Mermaid is for diagrams what Markdown is for text formatting: it is not always enough, but where it does suffice, it beats all other options — and, in most cases, it does suffice.

Mermaid is written in JavaScript. That’s OK, I mean, why not. It is easily integrated on websites, there are plugins for the commonly-used productivity systems, wikis and text editors, and I even can easily use it here on my Hugo site. Great! Yet mermaid is not (yet) ubiquitous and often there’s a need to compile the diagram into a picture — usually an SVG file — to paste in somewhere, or send to someone, or whatever. The online tool may not be always available, and firing it up is too much hassle anyway. I mean, I have some input data in the form of a text file, and I need an output file (SVG) generated from that data — that’s a situation that calls for a command-line tool. And there is one. The problem is, mermaid is written in JavaScript, and so is the command-line tool.

Running JavaScript in a web browser is easy, running JavaScript without one is a pain in the behind. There are myriads of dependencies that should be installed through NPM or Yarn, you need to install and configure Node.JS and Discordia knows what else. It may be OK for a developer (it might even be not as bad as Python) but you can’t seriously expect an end-user who just wants to run a command-line tool to dive into all this. So you do the reasonable thing: you bundle all the necessary stuff together and distribute your app in a Docker container. It’s harder for an end-user to set up and run than a compiled executable binary or a distribution-specific package, of course, but at least it can be reliably used. And it beats NPM or Yarn any day in any weather.

But just think about it: a whole bloody Docker container, with full-blown OS and stuff, just to run a command-line converter? In what universe is that a sane thing to do?! Even borderline normal?! Of course, JavaScript was never meant to be distributed to end-users in the form of a stand-alone app or a script file, like C++, or Go, or Perl, or Python, but a whole damned containerized OS to distribute a command-line tool that is 350 kilobytes of code including the tests and the documentation?! Really?

I’m not saying JavaScript is a total mess (although it certainly is). But people who use it to develop video editors, device drivers, and command-line tools need serious treatment.

Comments are webmentions.