Mathematics and Computation

A blog about mathematics for computers

Random Art and the Law of Rotten Software

Since the death of my old web server my Random Art has not worked. Bringing it up to date and installing it on the new server was a nightmare in software management. But it was worth it. The new Random Art runs the random art program inside your browser!

I implemented the old Random Art in 2005 with ocaml and cduce. Cduce is a programming language for XML which statically checks correctness of produced XML. I thought that nothing could be better than a web site that has an a priori guarantee of 100% complicance with strict HMTL. Those were the days of idealism.

Well, in 2010 it turned out to be quite impossible to reinstall Random Art on the new server. First of all, the current version of cduce is incompatible with the one from 2005. In addition, the old version of random art relies on old ocaml libraries that are not available in current Linux distributions, so I cannot easily recompile it. If I really wanted to install the old version, I would have to install an antique Debian system from 2005, but then I would suffer from old security holes. There must be a software equivalent of the second law of thermodynamics, let's call it the Law of Rotting Software:

“All software eventually fails, even if it you leave it alone.”

So it was clear that I should junk cduce and use something sane, like Django. (I know there is ocsigen, but as we say in Slovene, even a donkey steps on thin ice only once). I separated the ocaml code that computes random pictures from cduce and reimplemented the web site in Django. The site was up and running in no time! Except that all pictures were uniformly gray. It took me a week to figure out that this was caused by a change between ocaml 3.10 and 3.11 in how they treat mutable record fields inside function closures. It is still not clear to me exactly what the change is because I am not able to produce a small example that shows the difference.

I wanted to make the new site more user friendly by allowing users to generate their own random pictures. They would have to compute images inside their web browsers because I cannot afford a cloud of servers. So I decided to try Jake Donham's amazing ocamljs compiler that compiles ocaml to javascript. It worked, after a couple of days of making sure that the javascript code was equivalent to the ocaml code. I had to fix the pseudo-random number generator (which broke compatibility with the old random art), and remove a number of ambiguities about the evaluation order of arguments (ocaml evaluates  f x y in an undefined order, but usually right to left, whereas Javascript evaluates the arguments in f(x,y) from left to right). I am amazed at having 1200 lines of ocaml code run inside a browser.

Anyhow, I hope you will enjoy the new web site. Now I just have to make it work under Internet Explorer, which does not support HTML5 canvas element that I use for drawing (I suppose I just have to get Google's excanvas to work.) Also, I recommend Google Chrome over Firefox because its javascript engine is way faster.

Comments

Very interesting! Do you plan to publish the source code, at least the OCaml/ocamljs part?

Well, I am not to keen on publishing the part that generates images. That's where the real meta-artistic effort went in. But I plan to make another version that will be rendered instantly in javascript, and will allow pictures to be "mated".

Jack

From The Tao of Programming, Book 5:

A well-used door needs no oil on its hinges. A swift-flowing stream does not grow stagnant. Neither sound nor thoughts can travel through a vacuum. Software rots if not used.

These are great mysteries.

Andrej, I feel your pain! I embarked on the futile project of making a G3 Power Mac my web server, and even if I succeeded in the end the task left me somewhat scarred. It's not so much that software itself decays, it's the dependencies that diverge relentlessly. No matter how pure we write our code, it always depends on something else, and if we don't port our code it will be left behind, eventually.

[...] a comment » Random Art (by Andrej Bauer, via his blog.) The program accepts a string of text (the “name of a picture”) and uses it as a seed [...]

I'm surprised that you seem not to be aware of the term "bit rot".

Hugh

You probably either know this by now or don't care, but Unicode characters outside 7-bit ASCII produce different results on the Javascript version from the server version.

If my experiments and calculations are correct, you can fix this by calling unescape(encodeURIComponent(...)) on the input string before running the Javascript version. This converts the string to an explicitly UTF-8 coded sequence of bytes, which is the same format that's being used by your OCaml version on the server.

Deb

Andrej, I will watch for Random Art to be back, really miss it!

Benjamin Weaver

Well, it looks like it's been over three years since anyone commented. I'll just say that I love the Random Art generator/page/software, whatever you want to call it. I'm glad the page is still up. It has been invaluable to me. Thanks!

In a curious twist (which some might call "ironic", but I'm not sure that means what such folk think it means...) my browser can't quite guess what character encoding this page means to use. Specifically, I am seeing rogue "Â" characters in odd places, such as:

"There must be a software equivalent of the second law of thermodynamics, let’s call it the Law of Rotting Software:

“All software eventually fails, even if it you leave it alone.”"

Ryan Martini

Hello! I'm a recording artist. Would you mind if I used randomart for a music project on Bandcamp.com? I want to use the random art generated as inspiration for instrumental/ambient works and then post the works with the art.

Go ahead, just make sure you give proper credit.

Jacob Mays

Hello! I have improved JS version of your random art generator, so it works 20% faster. If you'd like to update it, please contact me.

Jacob Mays

If you want to view the code for JS version: https://pastebin.com/ShRHVUFX

How to comment on this blog: At present comments are disabled because the relevant script died. If you comment on this post on Mastodon and mention andrejbauer@mathstodon.xyz, I will gladly respond. You are also welcome to contact me directly.