Saturday 11 October 2008

(defun perspective (person) ( … ))

Dan Bikel has written a nice statistical CYK parser for Java, and it reads and writes Lisp syntax, namely Sexps. While I was coding on a project today, I was being watched and supported by a colleague. When I used Dan Bikel's Sexp class, hilarity ensued.
I countered her chuckles with an explanation of basic Lisp syntax. This prompted a curious reply of hers:
The inventors must have been lonely people.
Well, contracting 'symbolic expressions' to a word reminiscent of what computer freaks stereotypically lack may seem an awkward coincidence to some, but drawing a connection may seem like a stretch to others. Sadly, there probably is a grain of truth in such… assumptions.
Upon demonstrating to her some real world examples of Lisp code, and after the inevitable "all those parens!", she uttered
The inventors really must have been lonely people. And bored ones at that.
Poor Lisp. Is that what people think of you today?
Lisp is old. Very old. But just as Prolog, it is still around, and that alone justifies its use. In fact, most of what people use XML for nowadays should rather be done in Lisp syntax.

Wednesday 8 October 2008

Thou Shalt not Forget Those Who Are Afraid of Upgrades

I don't know how often I will have to curse about type erasure in the Java HotSpot VM. It is a pain in the… EVERYTHING. And the only reason for it is, of course, our sacred backward compatibility.
Some core library functionalities are utterly broken. How can a parameterized ArrayList's .toArray() return Object[]?
WHY??*
All because of type erasure. class Foo {{T[] = new T[42]; }} is illegal, because the runtime would have no clue as to what constructor to call for the array (it doesn't know its type). It boils down to: you cannot instantiate Generics. OK, you say, it wouldn't make too much of a sense anyway, but you see, it has side effects. Ever bothered to read the code of ArrayList and other parameterized standard collection types that use an array as a back end? Don't, if you want to retain your sanity. The heart of it is a lot of dirty casting, made necessary because of the way Generics are implemented (oh, the irony.)
One of the proposed features for Java 7 are Reified Generics, but somehow I doubt they'll make it into the language anytime soon. There's just still too many people around using a 1.4 VM (YES, Apple, we're looking at YOU) and introducing another substantial change to the way Generics work would make them even more complex than they already are (Yes, that PDF has more than 500 pages. Yes, it's mostly about Generics.) So, probably we'll have to just keep up with that crap. Microsoft did it right in .NET. Pity it's a closed platform.

</rant> [1] You have to first create an Array of your Type T (a literal type, not a Generic one) and then pass it to the overloaded .toArray(T[]).