I’m familiar with refactoring fairly large code bases in C# and Java but Clojure is something of a different beast, especially since it:
- Has a mix of macros and functions in typical code (i.e. you might want to refactor from a macro to a function or vice-versa?)
- Uses dynamic typing in most circumstances (so you don’t get compile time checks on the correctness of your refactored code)
- Is functional rather than object-oriented in style
- Has less support for refactoring in current IDEs
- Is less tolerant of cyclic dependencies in code bases (making it harder to move blocks of code / definitions around!)
Given the above, what is the best way to approach code refactoring in Clojure?
In “Working effectively with legacy code” Michael Feathers suggests adding unit tests to create artificial “inflection points” in the code that you can re-factor around.
a super brief and wholly incomplete overview on his approach to adding order to unstructured code:
The recursive approach seemed to fit well with the mental processes I use in thinking about Clojure so I have come to associate them. even new languages can have legacy code right?
This is what I got from my reading of that one book while thinking about clojure. So I hope it is useful as a general guideline. perhaps your codebase already has good tests, in which case you’re already beyond this phase.