Posts

Showing posts from November, 2012
Micah Martin has done   the Coin Change Kata  in Clojure. His collegue did it in Ruby (presented in the end of the Micah's post). I don't like either of the solutions. The Clojure one is almost unreadable - it's extreamly hard to understand what's really going on - take, map, mapcat, repeat - it's just too many too general constructs for such a simple problem. The Ruby one is readable and straitforward, though it's imperative and uses mutable vars, which I don't like very much these days. So, let's look at what code I wrote in 5 minutes in F#. What's interesting, it worked the first time as was compiled:

Maybe monad in F#

F# supports writing custom monads very well. Take a look at (famous :) maybe monad which is just 6 lines of code:

->, ->> and thread-it

One guy suggested to use -> macro as often as possible instead of ->>. However, his final code doesn't look as clear as it should be (yes, it *should* be: we're coding in clojure). I think, this is a great opportunity to use wonderful thread-it macro from "Clojure in Action" book:

Clojure: Multimethods vs Protocols

Let's measure how much multimethods are slower that protocols: multimethods are roughly as fast as protocols clojure maps as fast as records "class" notation is in order of magnitude slower than "map" notation