C as a scripting language
The title of this card is slightly joking, but I’m also completely serious.
My RetroV javascript library has a minified retrov.min.js
version available as
part of the repo. I was relying on external tools to produce the min file.
But I prefer to keep projects self-contained whenever possible because I’ve found that it’s really hard to maintain things over the long run if they depend on anything outside the project.
Douglas Crockford’s JSMin https://www.crockford.com/jsmin.html is a mere 319 lines of C.
So I decided to essentially treat it as a script. I compile it and run it in a shell
script (minify.sh
) in the RetroV repo:
#!/bin/sh cc jsmin.c -o jsmin ./jsmin <retrov.js >retrov.min.js
It compiles and runs in a fraction of a second, so there’s no reason to store the
binary with the project. (Also the jsmin.c
file is half the size of the compiled
binary.)
As long as a C compiler named cc
(symbolic link to /usr/bin/gcc
in my case) on
your system, this just works.
Back to computing