Monday, May 10, 2010

Better performance in App Engine with new Lisp language Clojure

This post is part of the Who's @ Google I/O, a series of blog posts that give a closer look at developers who'll be speaking or demoing at Google I/O. This guest post is written by Stefan Richter, founder of technologies and creator of TheDeadline, an intelligent to-do manager running on Google App Engine. TheDeadline will be demoing as part of the Developer Sandbox.

On Google App Engine, Google's cloud computing platform, developers can officially choose between two languages -- Python and Java. In the last couple of years, a large number of new programming languages were created and existing popular languages like Ruby were ported to run on the JVM. The good news: now almost any programming language that runs on the JVM should run under Google App Engine, too.

When I read Paul Graham's Book "Hackers & Painters" back in 2004, I was especially fascinated by his essay "Beating the averages" about his start-up company that was using Lisp as the main programming language.

In 2009, when we started TheDeadline, we chose Clojure, a new Lisp language running on the JVM, as our main programming language, and we decided to use the Google App Engine Cloud Computing infrastructure to run our system.

Paul Graham was right. Here is what we have learned:

1. Functional Programming with Clojure really makes you more productive. We have a small team of three people with a background in Haskell and Common Lisp. We release a new version once a week and we estimate that we only write 30% of the code we would have to write in Java and about 50% of the code we would have to write in Python. Writing less code requires less time.

2. Clojure gives you powerful functional abstractions over simple data structures. Writing less code means that this code must be much more powerful. As opposed to object-oriented programming where you build complex object-graphs using inheritance and composition, in functional programming, you are using simple data structures and powerful functional operators that work on these data structures. Internally TheDeadline uses a set of specialized mini-languages, also called Domain Specific Languages (DSL). We are using these mini-languages as the higher-level building blocks for our application.

3. Using Clojure on Google App Engine feels very natural. It is very easy to access the App Engine SDK from Clojure as well as to integrate other existing Java libraries. App Engine's datastore fits especially well with Clojure as we use simple maps as data structures. These can be stored directly into Google's distributed key-value datastore.

If you want to learn more, I invite you to read a more detailed technical posting on our Hackers with Attitude blog about a very simple Clojure mini-language to access the App Engine datastore.

Clojure in combination with Google App Engine became a competitive advantage for us. We are able to build new features quickly with a small team. With Google App Engine we have a zero-maintenance, low-cost cloud computing infrastructure designed for large-scale applications.

If you are curious now and would like to try out TheDeadline, you can sign up here. For more Clojure and App Engine related posts, you can follow our blog H.W.A. If you're attending Google I/O 2010, you can chat with us about Google App Engine, Clojure and the Universe in the Developer Sandbox on May 19 and 20. We look forward to seeing you there.

by Stefan Richter, founder of


  1. Just a few questions for languages that run on top of the JVM platform such as Clojure - 1) are there any aspects of the java programming language that are missing or can you accomplish all of the same things you can accomplish using java? 2) is it possible to use java and Clojure together since it will all be compiled to java bytecode in the end anyway?

  2. @Jim, I'm obviously not the article writer, but as for Clojure it has very good interoperability with Java.

    It has a lot of syntatic sugar to make calling Java from Clojure code very simple.

    Consider this example from the Clojure website:

    (. javax.swing.JOptionPane (showMessageDialog nil "Hello World"))

    or this line from one of my recent experiments while teaching myself Clojure:

    (.. Runtime (getRuntime) (exec (str "wget -q" num ".tar.gz")))

    Basically, you can do *anything* you can do in Java in Clojure.

    You can also can also do things going the other way but it's not as direct.

    Now, this is not necessarily true of other languages on the JVM. I personally don't think any of them have as well thought out/implemented interoperability with Java...many of them have little, more complex systems for it, or even none at all.

    I'm just getting started with Clojure, but so far I am really really liking it. I highly recommend checking it out.

  3. @ThomasB - Thank you, will do!

  4. Note, there was a lack of ability in Clojure at one point to handle annotations, but unless I missed something, it was finally being added in 1.2 (the new version that is not in final stable release yet but is coming soon to that form, barring problems).

  5. Not to mention JavaScript which has been interoperating with Java for years and is included in the JDK.