Skip to main content

Posts

Showing posts from 2009

K ?

Whisper the terrible words type erasure to any moderately experienced Java programmer and you're likely to see: fear loathing soul-crushing sense of defeat all of the aboveNow if you are a moderately experienced Java programmer, but you're thinking to yourself "what's type erasure ?" my advice is this:
Stop reading now !
Sometimes ignorance really is bliss.
My own rule of thumb, when confronted by the need to query the identity of K, or V, or T or any of their evil friends, in the innards of a class with generic type parameters, is to run away. Sadly, there are circumstances when that's just not an option. Although I deeply empathise with those who equate Java reflection with incest and folk dancing there are times when it's black magic or nothing. But where to find the magic ?
Enter Richard Gomes and his article: Using TypeTokens to retrieve generic parameters. This demonstrates the seemingly impossible feat of pulling erased rabbits out of Java's hat.…

PragProWriBlockMo

PragProWriMo has been even more challenging than I'd feared thanks to my sub-gnat concentration span and memory like a... you know, round thing with holes. While others have been trotting out chapter outlines, finding their voice and defining their readership, I've been shuffling along the beach of irrelevancy and gazing out at the ocean of unfinishedness.

It's amazing / pathetic / pathological (select all that apply) just how intimidating this simple daily writing exercise has become. The main problem has been the notion of a book hovering over the writing. No matter how many times I've told myself to treat the writing as a pump-priming exercise rather than an examination, I haven't been able to shake the anxiety of not "seeing the book" in my mind's eye.

But I will not surrender ! Well, that's not quite true because I did a few days ago, giving up on the whole thing as too hard. Now though, I'm putting the white flag back in the cupboard and …

PragProWriMo begins

November is here and this not-so-young-anymore geek's heart has turned to writing. I'm taking up the challenge of PragProWriMo by committing (forcing, tricking...) myself to write every day. The target is eighty pages by the end of the month.

As someone who has routinely taken years to write an eight page scientific paper (only four pages really if you subtract the tables, figures and compulsory, gratuitous citations of the publications of those who you suspect might review your paper) eighty pages seems an imposing target.

Ah well grasshopper, the longest journey etc. etc.

My chosen geek book working title is Biological Models in Java. That's likely to change as the writing progresses of course... I can already see it wandering towards Mathematical Recreations in Java, Ruby, Groovy, Clojure, R and that other language (you know, the one with the clicking sounds).

Unleash your inner literary geek

Those good fellows at Pragmatic Programmers have come up with the geeky equivalent of NaNoWriMo - the annual event that encourages people to try their hand at writing - which they have christened PragProWriMo.

This is the chance for you to get started on that brilliant computing book that's been festering in the back of your mind for the last few years. All you have to do is commit to writing a few pages every day throughout November. And yes, every day means every day.

I'm planning a tome on displacement behaviour myself...

Measures of confusion with JSR-275

I love the idea behind JSR-275, a units of measurement API for Java (see here for a background article by Jean-Marie Dautelle, the lead author) but I wish there were more examples out there about how to use it properly.

I'm presently writing some code for a spatial simulation. I want the user to be able to specify constraints on spatial entities such as their maximum area, width, movement over time and so forth. Bringing JSR-275 to bear on this means that I can use a consistent set of units within the code while leaving the user free to express their input data in whatever units are convenient for them.

The theory is beautiful but my, alas, my code is ugly.

Take this snippet for example...
// get a constraint from the user
Constraint constraint = ...

// get the unit used internally for this constraint (e.g. "m")
Unit<?> stdUnit = ...

// the value for the constraint (in the user's units)
double value = constraint.getValue();

// get the label for the user's units (e.…