Sunday, June 8, 2014

Kata: FizzBuzz in Clojure with Midje

I did the FizzBuzz kata in Clojure using Midje.
You can find the resulting code in GitHub.

I love Midje's readability. Look at the tests:


This is the FizzBuzz code in Clojure:


Compare it to this version I did in Racket's Advanced Student Language some time ago:


They are more or less the same (except that Clojure's version returns a string whereas Racket's one returns a list of strings).

On one hand, I prefer Clojure's cond which is more readable because it's more lenient with the parentheses.

On the other hand, I really like how Racket's local allows to define local functions inside another function in the same way they are defined in a module.
In Clojure I also defined a local function is-multiple-of? using let but the result is less readable than using Racket's local.

Update: I keep on working on this kata on the next post, Practising Clojure sequences using FizzBuzz and REPL Driven Development.

No comments:

Post a Comment