Tuesday 20 September 2011

Clojure on Heroku

Here's a quick link to my simple "Clojure on Heroku example" Git repository .


To quote the readme:

"A very (very) simple example of Clojure + Compojure project that can run on Heroku's Cedar stack"

Wednesday 10 August 2011

A simple Clojure web app

I thought I'd start with a simple example showing why I'm coming to love Clojure. This is a small web app that accepts a GET request with an id, hits a CouchDB database, executes some simple business logic then returns the results as json.
What's interesting is that it does all this without using business objects, mappers, etc.

Clojure allows you to deserialize the json response from Couch into a hash-map and access the elements of that hash-map via symbols like so (client :address), no need for strings or accessing by a numerical index. As you can see this allows you to access values in the hash-map like fields on an object.

Clojure also has a thrush (or pipe) operator -> which can be used to pass objects into methods. While this is only syntactic sugar it allows you to use functions as if they where methods. e.g:
(-> client print-name-and-address)

This approach may not meet everyone's needs but I think it's a really great way to make lightweight, easily extensible, data driven web applications.
In the following example all the code is lumped together in 1 file just for the sake simplicity. In production code you would probably want to brake functions out into separate files for those that work on json, documents & vehicles as well as the core routing logic. (Error handling has been omitted to keep the example simple)

Friday 29 July 2011

A fresh, new, start

Hi all,

Sorry for the lack of updates but it's been a busy year.
Soon after my last F# post I landed a pretty cool job. I've since been learning Python and a bit of Ruby/Rake.

But I have to say the language I'm really psyched about this year is Clojure... It's functional, it's JVM back-end means it's portable but most of all I like the fact Clojure has made Lisp trendy in this day and age; like some ancient, elder thing rising from obscurity to take over the world.

So, as you may have guessed, my next few posts are going to be very Clojure-centric.