Updated: A day (wasted?) with Groovy

Update: After staying up late (after 2am after the clocks went forward), I found various bugs – I don’t know if these reflect underlying changes in the language or the JVM in the interim but it seems to work now (see GIF of the Game of Life below). Working on getting the jar done too so it becomes easier for others…

There has been a small revival of interest in the wonders of 8 bit computing lately and I thought now would be a good time to revivify the BINSIC project. But has all proved to be a highly frustrating waste of time.

BINSIC – BINSIC Is Not Sinclair Instruction Code – was my 2012 project to build a DSL in Groovy that would allow users of modern computers to write and run ZX80/81 BASIC. I wrote it to explore whether it was really easier to make instructive programs that explored basic mathematical and scientific problems back then.

The first problem I had was that Groovy (and this behaviour wasn’t advertised as far as I could see) simply would not run code written in block capitals. So a DSL was essentially out and I had to write something that was more (much more) like an interpreter.

But it worked, mostly, and I had some fun with it, turned it into a jar file and forgot about it.

Unfortunately the machine hosting the jar file is gone and I never got around to trying to rebuild it – until today. And now I find the code from 2012 just won’t work.

If I try to run that code I get this:

Why code that ran a few years ago won’t run now is a mystery, but replacing the empty element in the list will get it to run – a bit – and this gets me something from the Game of Life I wrote in BASIC:

But again something that worked well 8 years ago now breaks the system:

On top of all that I seem unable to build a jar file on the command line, unable to install Eclipse and unable to get NetBeans, which will let me install a Groovy plugin but not use it, to work properly.

Making sense of Android’s complex development process

Image representing Android as depicted in Crun...
Image via CrunchBase

Back in about 1997 I bought a book about this new programming environment – it seemed something bigger than a language but smaller than an operating system – called Java.

Back then the idea seemed great – write once, run anywhere – but there was a lot of scepticism and, of course, Microsoft tried to poison the well through the tactics of “embrace and extend” with their J++ offering. All of that made it look as though Java was going nowhere.

I wrote a couple of applets – one was a “countdown” timer for Trevor Philips‘s mayoral election website in 1999, another was a SAX based parser for the largely Perl-based content management system I wrote for the Scottish Labour Party the following year, ahead of the 2001 election. But no one seemed to like applets much – it seems ridiculous now, but the 90K download needed for the SAX parser really slowed down the Scottish party’s site, even though I was pretty proud of the little newsticker it delivered (along with annoying teletype noises as it went). I forgot about Java.

But, of course, that was wrong. Java is programming language du jour these days, though Microsoft’s responses to the success of Java and the failure of J++, C# and .net, are also big.

Android is, of course, Java’s most prominent offer these days – literally millions of people will be running Android apps even as I write this and thousands of Android phones are being bought across the world daily. Time to get reacquainted, especially as my new job is once more about political communications.

But, as I discovered with C++ when I came back to it after over a decade for my MSc, Java has moved on a fair bit in that time and, unlike C++, I cannot say all the progress seems to be positive. Indeed Java seems to thrive on a particularly ugly idiom with developers being encouraged to write constructors of anonymous classes in the headers of functions – ugh.

I can certainly see the beauty of Groovy more clearly than ever, too. Though being an old time Perl hacker makes me resent Java’s heavy duty static typing in any case.

To help me through all this I have been reading O’Reilly‘s Programming Android: Java Programming for the New Generation of Mobile Devices. Now, usually O’Reilly’s books are all but guaranteed to be the best or close to the best of any on offer, but I have my doubts that is the case with this one – it seems to be sloppily edited (eg at different times it is difficult to follow whether one is being advised to use the Android SDK or the Eclipse editor) and falls between being a comprehensive introduction to Android programming and a guide for Java hackers to get on with it. It feels less than ordered, to be honest.

Now, maybe this is a function of the language and the complexity of the environment, I don’t know. But I would welcome any alternative recommendations if anyone has some.

Going to have to try eclim

MacVim icon, glossy style
Image via Wikipedia

For my MSc project I made heavy use of the Eclipse IDE to write various Groovy programs that took an XML input and output an SVG (of course SVG is XML also, but I hope you understand).

Groovy was a great choice as, while not as fast as C, for instance, it was easy to write something that could hack XML and SVG – all I had to worry about was the algorithm as much of the infrastructure for handling the file formats was to hand.

And Eclipse made perfect sense as the IDE as it had good Groovy support.

But my problem was I am a VIM user most of the time and so there was more than one time when I had to go back and clean up the :w mess I had left behind.

Now, it seems, there may be a solution to hand – eclim – which allows me to use VIM in Eclipse and vice versa. I will try it in the next few days and see how I get on.