September 30, 2011

Groovy Graphs

As a software developer you're probably no stranger to SQL databases. There's every chance you even had to take seriously boring courses on database normalisations, and all forms of joins. In fact, I even taught some very basic SQL to biology and bio-engineer students (sincere apologies to them :).

What's more interesting is that the last decade or so has seen the rise of a NoSQL movement which is trying out alternative database schemes. They trade of some of the ACID properties in order to gain greater scalability, greater performance, etc. You might have heard of Google's BigTable, for instance, which is like a giant distributed dictionary (or HashMap, for the Java crowd).

One category of NoSQL database which interests me is graph databases. These focus more on the relationships between entities, and efficient matching of these. This could be useful if you wanted to, for instance, query complex syntax trees to do program analysis. Or maybe in a genealogy application where your users want to do complex queries on their family ancestry.

So I have been playing a little with one such graph database, which is Neo4J. It's open source, Java based, and has a very simple API. It integrates Lucene for indexing and quick retrieval of nodes, and has support for doing quite complex graph traversals. If there's a feature I'm missing it's one of graph matching, where you could give it an example graph and let it find matching instances in the full one.

Neo4J gets even better when you add in a bit of Groovy. If you check the design guide this is how Neo4J recommends you to implement your business classes in Java:

public class Student {
    private final Node node;
    public Student(Node node) { this.node = node; }

    public void setName(String name) {
        node.setProperty("name", name);

    public String getName() {
        return (String) node.getProperty("name");

    // And so on for other properties...

That's a lot of boilerplating going on for those properties. Groovy metaprogramming the rescue!

PropertyContainer.metaClass.getProperty = {name ->
PropertyContainer.metaClass.setProperty = {name, val ->
    delegate.setProperty(name, val)}

(I found this here, btw.) With those three lines you can now do:

def node = db.createNode() = 'John Doe'

So no more need for special business classes. You can now use nodes directly and read/write properties on them as if they were plain old objects. With a bit more Groovy magic you could even set this up so that assigning one node to a property of another node creates a relationship between those nodes instead. And Groovy guru's might even map GPath expressions to graph traversals. And then you're creating and navigating graph databases as easily as you do object graphs.

Now that's cool.

September 29, 2011

Make Install: Diaspora

We all love to hate our Facebooks and Google plusses, but here is something which puts you firmly in control of your own data: Diaspora. It's an open source peer-to-peer social network. If you wanted to, you could host your own data on your own server, and it would still integrate seamlessly into the overall network. You can even move your data around different hosts as needed.

Amazing to see this come together. Especially if you consider this started out as the work of four enthousiastic developers (Daniel Grippi, Maxwell Salzberg, Raphael Sofaer, Ilya Zhitomirskiy) over the course of one summer. And it's all built in Ruby on Rails.

For the software developer geeks, there is also a blog which is presenting some of the design that went into Diaspora. Here, for instance, is a discussion of how the different users get connected in this peer-to-peer setup.

September 20, 2011

Java^H^H^H^H Groovy

I have had the opportunity to work with Groovy over the last few weeks, and I though I would share my main conclusion: it is vastly better than Java. Killer features ? Yeah, a few:
It's actually quite embarrasing that Groovy manages to deliver in a few years what Java failed to bring to the table in much much longer. What have been the greatest changes to the Java language in the last few versions ? Generics ? Better iterator integration ? Yeah, not much worth mentioning.

I also learned how much I got stuck in the Java view of programming. It actually took some time to readjust to some of the Groovy features. The advantages of closures, for instance, are many. But it required conscious effort to apply them when I started in Groovy. So here's the biggest reason every Java developer should be playing with Groovy: because it can make you a better programmer with better reflexes.

September 07, 2011

Make Install: Dandelion

Pretty impressive work by Ragnaroek: Dandelion is an Eclipse plugin for doing Lisp development. Apparently it comes with support for SBCL and CLISP.
Haven't tried this yet, but I definitely could have used this when I worked on my 3D engine in Lisp. Remember that one ? Good ol' times. :-)