A coworker pointed me to yet another “better Java” named Xtend. I currently have to use Java in my day job because of the excellent support to access MSSQL server. After fighting with Java for some days now, I hoped Xtend would make the job a little more pleasant. After tinkering a bit and stumbling a few times over the static type system I came across a real glitch, at least for me: the ubiquitous “reduce” function. It is realized as an extension method, which means one can simply call reduce on every iterable and its subtypes, and it looks quite neat:[gist https://gist.github.com/4155273]
But there is one big problem with it: the elements in the iterable and the return value have to be the same type! I have never encountered a real world case where I would want that behaviour. Another thing I missed is a optional start value. The following gist shows a different prototypical implementation of reduce, with an initial value and a return value of a different type:[gist https://gist.github.com/4155191]
I’m not sure why the original implementation is so restrained. Maybe future versions will make it better. Except the painful static typing and this glitch I think Xtend is quite amazing and can make me more productive in the Java world.