Archive for April, 2007

Equal opportunities oriented programming

Tuesday, April 24th, 2007

There’s a common feeling I get when programming in Java. “Shit. I can’t do that. Methods aren’t first class citizens”. The same holds (in greater generality) for types, code, macros, tables and a variety of other things.

Some of these problems have solutions in the works. First class functions have of course been around for ages, dependent types are giving us first class types, multi stage programming gives us first class code and macros. Not sure about tables, but that’s probably because I don’t know enough database theory.

Common theme here: Anything which is not a first class citizen in your language will at some point become a pain when you want to manipulate it as one in order to get the right abstraction for your problem.

I wonder how far we can get around this? Certainly the various lisps seem to come the closest, but I’m not sure they go far enough.

Tail call optimisation in Javascript

Monday, April 23rd, 2007

I just happend across this old link

Basically it’s a (surprisingly elegant) way of creating tail call optimised functions in javascript.

There’s a slight subtlety with it unfortunately - you can’t simultaneously have a function call itself in a non-tail recursive manner. If you do it will break things.

It claims to support mutually recursive functions, and I think this is true, but I bet you’ll find there are some finicky details which can cause the stack to grow unboundedly before the optimisation kicks in, and I think you might have trouble properly optimising mutally recursive calls in this manner.

Still, very cool.

Viral XKCDing

Saturday, April 21st, 2007

Pardon me while I maliciously subvert a viral marketing campaign. :-)

THE ALGORITHM CONSTANTLY FINDS JESUS
THE ALGORITHM KILLED JEEVES
THE ALGORITHM IS BANNED IN CHINA
THE ALGORITHM IS FROM JERSEY

Blatant and malicious evil

Friday, April 20th, 2007

From freenode ##java:

10:13 < DRMacIver> cybereal: Oh, I figured out how to work around the Java type system to make my generators work. It requires a bit of a rearchitecture though.
10:13 < DRMacIver> It’s blatant and malicious evil I’m afraid. :)
10:13 < cybereal> That seems to be the way of things for you lately

More JTypeBuilder

Friday, April 20th, 2007

No further work done on it at the moment, but that’s because I’m rethinking its architecture.

Rather than building a DSL, I think it’s much more sensible to use abstract Java classes as the templates, with the generated classes subclassing a user defined abstract class and the abstract methods and annotations defining which methods are going to be generated.

This will let me switch to a more APT centric approach. I’ll probably start using apt-jelly for this, as it works quite well with the existing freemarker based approach.