From the archive

Why Clojure works

When I started working in my current position in a well known investment bank in foreign exchange, I was the biggest functional programming advocate in my team.

So basically I was trying to sell Clojure to a team of very experienced Java developers who are good at large scale high availability and low latency softwares. Their first impression were like “Are you kidding me? You idiot are trying to get us to use some dynamic language with no mature IDE support for mission critical trading platform code? Like Javascript!”

After couple presentations selling catchy terms like “immutability”, “referencial transparency”, “higher order functions” blah blah blah, they finally got to a point being curious enough that they want to try the weed that I have been smoking out there in the woods too.

The first thing that I got them to try is REPL. How do I know how “into” works? REPL it. How do I know how http-kit works? REPL it. How do I know if the defn I just wrote will behave correctly in runtime? REPL it. Because most of the things in Clojure are just functions, there is nothing to stop me from giving it a go with just data and verify the result right away in REPL.

The second thing that I want everyone doing is Tests. Oh you wrote a function? Give it some unit test cases. It’s so easy, remember those expressions in REPL that you wrote testing your function? Copy those over to be your test cases. What is a unit test in Functional Programming? Plug in some data, then make assertions of what data are you expecting — it’s just data, easy to write, easy to try and easy to read. No mocking 15 classes to satisfy you awesome object creation, and no mocking methods for your mocking classes.

By the time project code base had gain significant size, I have a system that is heavily tested: either from REPL, or from test cases. Code refactoring? Go ahead, just make sure all tests are passed. A weird runtime error? Fire up the REPL and reproduce it, and then you guess it, write a test case with that data reproducing the bug, and make correction in your code to make that test pass.

In the end, you want an IDE with awesome debugging break point features? REPL is better. You want a nice type checking system to make sure everything is align? Tests and functions are a natural couple. And that is how I found out Clojure really works.

Archiveretrieving memory…