Managing large codebases in Clojure

Of course. It’s a little hard to explain, but I’ll try my best.

What I mean by this is that you want to try and split up your logical operations and their control flow.

If A, B, C are the operations you need performed. Lets assume all of them need no input data and simply print out their names.

(defn A [] (println "A"))
(defn B [] (println "B"))
(defn C [] (println "C"))

Now say you want to print ABC? It’s often tempting to do:

(defn A [] (println "A") (B))
(defn B [] (println "B") (C))
(defn C [] (println "C"))

(A)

Creating a deep/nested call stack, where you’ve coupled your operations and their flow together.

Instead favor a shallow/flat call stack:

(defn A [] (println "A"))
(defn B [] (println "B"))
(defn C [] (println "C"))

(do (A) (B) (C))

With top level orchestration.

Hope that clarifies it.

5 Likes