Unicoding

A recent thread on the Clojure discussion group, which linked back to an earlier thread, reminded me of my favorite snippet of code I’ve ever written:

(let-> ★ 2 (+ ★  3) (- 10 ★ ) (map #(* ★  %) [2 3 4])) 

This code “threads” the star value () through the code, first binding it to 2, adding 3 and rebinding the result, subtracting it from 10 and rebinding the result, and finally multipling it across the vector [2 3 4]. While the computation is trivial, I love how the non-alphanumeric character jumps out of the code, making its presence know. While I wouldn’t suggest littering every line of code with characters not on your keyboard, perhaps judicious use of unicode glyphs would make programs more readable.

Non-ASCII programming has never really caught fire. APL dates from the earliest IBM mainframes, and has several successor languages available for modern hardware, but has never seen a great deal popularity. Note, however, that APL required the use of a specialized character set. Optional use might prove more appealing. colorForth used different colored text to provide additional semantic information. I could see the value in making the source code more readable, but neither colorForth nor Forth have seen a wide interest. For both APL and colorForth, the reasons for a lack of success are probably unrelated to their use of characters or color, but rather to the fact that neither are in the ALGOL/C/Java family of block languages, which dominate modern programming practices.

Many languages today allow for Unicode characters, including Java. Perhaps the biggest barrier to using unusual characters in source code is the difficulty of typing them out. To create the snippet above, I had to drag the star glyph from a palette into my text editor. For programmers that avoid the mouse (e.g. me), this could be a show stopper. At the same time, it should be possible to find or define keyboard equivalents for some of the more useful glyphs. I’m going to experiment with their use for variables that I might otherwise give uninformative names, such as tmp or x, or in places that require a little visual pizazz to make the code clearer. It should be a fun experiment.