A few words from Agical

Why you should try Clojure Interactive Programming

Clojure has a lot of things going for it. To name just a few: Functional programming is the default. Clojure makes it easy to keep data immutable. The language is small and simple, and the programs you create stay smaller and simpler than with most programming language environments.

Still, perhaps Clojure’s super power is Interactive Programming. I.e. using the REPL to connect to, inspect, and modify the running program as you are developing it. As a Clojure developer you can leverage this power for fun and for profit. The Clojure REPL will quickly let you verify that your changes are in the right direction, or give you early feedback that you need to think differently about the problem.

The immediate feedback of the Clojure programming mode should be contrasted to the much more common development cycle – until done:

  1. Changing your program

  2. Compiling it

  3. Running it

  4. Setting it up so that it exposes the piece you are developing

  5. Testing it

Depending on the program, the compile step can be pretty lengthy. And restoring the program state so that you can test your changes can be quite laborious. We are so used to this way of programming that we do not question it, and do not stop and wonder about the amount of time and energy it wastes. However, after having experienced Clojure’s super power, returning to this other programming cycle stops making sense.

With Interactive Programming the steps above are broken up into two activities: You first start your program, and then keep it running while you hack on it and test your changes. Step 1:

  1. Starting your program together with its REPL (the REPL is a service running together with the program that allows us to interact with, and change, the program while it is running1).

  2. Setting the program up to where you can test the piece you are developing

  3. Connecting your editor to the program’s REPL

Some development sessions will have you restart the program only very occasionally, sometimes as seldom as once every two or three weeks. In theory the whole program could be built, from nothing to something, without ever being restarted.

Instead of recompiling, restarting, and restoring program state, you will spend your time and energy in activity 2: in Interactive Programming development mode – until done:

  1. Changing your program

  2. Testing it

The testing step is often as short as inspecting the result of calling some function without even leaving your editor. Other times it involves actually using the program. Since your editor is connected to the program you are developing, both methods work for checking that the program behaves as you want it to behave.

Working like this, the feedback on your changes is immediate. It soon starts to make perfect sense that your program is mutated, according to your command and without losing state, while it is running.

Gone is the waste. You are left with the fun and the wonderful feeling of being productive, adding verifiable business value at top speed.

To see it in action, check this video out, where Clojure expert Pavel Klavík applies Interactive Programming to the backend, frontend, and even production of Orgpad, an interactive whiteboard built with Clojure and ClojureScript:

To see a simpler example, you can also check this video where I solve FizzBuzz in some different ways, using Interactive Programming:

To start learning Clojure in this Interactive Programming way with Calva for Visual Studio Code, please head over to:

Happy interactive coding!

  1. Clojure Interactive Programming is enabled by the REPL, which is why you will also sometimes see it referred to as REPL Driven Programming. While the REPL is powering the REPL prompt (which many Clojure programmers hardly use at all) its main use is to connect the editor to the Clojure program you are developing.↩︎