Managing highly repetitive code and documentation in Java

For people that absolutely need performance, boxing and unboxing and generified collections and whatnot are big no-no’s.

The same problem happens in performance computing where you need the same complex to work both for float and double (say some of the method shown in Goldberd’s What every computer scientist should know about floating-point numbers paper).

There’s a reason why Trove‘s TIntIntHashMap runs circles around Java’s HashMap<Integer,Integer> when working with a similar amount of data.

Now how are Trove collection’s source code written?

By using source code instrumentation of course 🙂

There are several Java libraries for higher performance (much higher than the default Java ones) that use code generators to create the repeated source code.

We all know that “source code instrumentation” is evil and that code generation is crap, but still that’s how people who really know what they’re doing (i.e. the kind of people that write stuff like Trove) do it 🙂

For what it is worth we generate source code that contains big warnings like:

/*
 * This .java source file has been auto-generated from the template xxxxx
 * 
 * DO NOT MODIFY THIS FILE FOR IT SHALL GET OVERWRITTEN
 * 
 */

Leave a Comment