Random thoughts, daily life, being a student, quantum computing.

2007-07-09

Haskell and Java

In my day job, I program with Java. In my grad studies, where I'm working on a Ph.D. in Computer Science, I program with Haskell. Most of my research involves computer languages, my Masters thesis was on creating a quantum programming language, including an operational semantics, a simulator and a compiler. The compiler and simulator were written in Haskell.

I like Haskell. It appeals to the way my brain works. Being a functional language, it tends to be less verbose and "It just works." The last part refers to the fact that once you have the types defined correctly and the compiler accepts your program, it often is correct. The amount of debugging tends to be minimal.

Java, as you may know, requires a lot of debugging. Null pointer exceptions, class cast exceptions in collection objects (we are still stuck at 1.4 at work), and general algorithm problems.

So, when I get any chance, I sing the praises of Haskell vs. Java. This last week, I needed to create a small tool that would check consistency of the CVS Repositories in a project. Sometimes, my developers get a bit excited, copy over code or supporting files to a new directory and neglect to remove the CVS information from the copied files. (Sigh!). So, a nice simple directory walker that checks the consistency is all I needed. I thought - why not Haskell? So, I wrote it up in Haskell, using GTK2HS for the interface.

After showing it to my team, one said "Gee, that would be nice to have as an ant task". I thought so too, so I resolved to do that on the weekend.

Much to my dismay (and depression). The Java code was shorter, simpler and faster to write. Why?

Well, some of it is due to the interface documentation. My GTK2hs code involved using a tree list, which is new with the latest release ot GTK2HS and required a bit of trial and error. The Ant task documentation in the O'Reilly ant book is excellent.

Some of it is due to the interface. Any one who has programmed with gtk knows that there is a lot of setting up to do the simplest screen. Ant tasks, on the other hand, have a pretty direct and simple interface to the world.

Lastly, and this is the really sad part, I'm probably faster with Java lately, as that is what I use day to day. Sigh.

No comments: