Slow restarts are killing your productivity. Can Clojure save you?

Our Java and Spring webapp may take 5-10 min to restart after a change on my PC, especially when something else (such as IntelliJ) is using the CPU. On Friday I was trying to factor out a new endpoint and it took me about three attempts to get it right. Every time I had to wait for the behemoth to restart to discover that my code was still broken.

And that is why I love Clojure with its interactive development, which provides me an immediate feedback. You could argue that if only I knew Spring better and were a better programmer, I could have made the change right the first time. And you would be right. But I am not that good and, even though I like learning, I do not feel like learning Spring perfectly before coding anything. (I would actually prefer not to have to learn Spring at all, but that is another story.)

The application takes so much time because I have an old computer and because it first waits for Gradle to compile the changes, which takes a while, then on Spring to start and do all its auto-discovery and configuration, then on fetching data from our configuration service. This is certainly a rather bad case and in your app you could arguably get the restart time much shorter. But even if you sped it up all you wanted, there would nevertheless always be some delay between a change and being able to test its effect. (Only tools such as JRebel can help to bring it sometimes to 0.) A delay that will break your development flow (though you might not realize it, if you are used to never being in the flow :)). Moreover, a restart wipes up any state you had and need to rebuild to be able to check the change. But this is actually only a half of the problem.

The other half of the problem is that nothing - neither the build tool, nor the framework, nor the application - is optimized for giving you a quick feedback. In Clojure land it is not just the language itself but the whole ecosystem that is designed for interactive development and thus as quick a feedback as only possible. As an example: In the standard Java stack, I will either need to go through the browser or curl my API to check a change. That is not the case of Ring, the Clojure web framework/standard. As most libraries in Clojure do, it favors simplicity, substantiated by its founding elements being just data and pure functions. Thus I can easily capture the incoming request once (if I do not want to make one from scratch because I am not sure how the app sees the request) and then use it, perhaps modified, from the REPL to call my app or a particular handler directly, as many times as I need. (Which is close to impossible with the beast of the Java Servlet Request, which is like the banana held by the gorilla…​..)

Summary

To be maximally productive, I need to be able to make tiny changes and get an immediate feedback on their effect. This requires a language and libraries that were designed to support interactive development. And the only language + ecosystem I know that does this is Clojure. Your mileage may vary - but I got truly addicted to the flow of the immediate back and forth between my thoughts and my code, building iteratively and interactively both my understanding and the software. Your productivity likely also suffers from the long feedback loops, whether you realize it or not. Think about it the next time you code, and perhaps give Clojure a try!

PS: I used to be a heavy proponent of unit testing. It is the best thing you can do in Java to get a faster feedback loop but it still is a far cry from Clojure’s interactivity, especially if any state is involved.

PPS: Nowadays the problem of slow restarts applies not just to Java but also to Node.js and even to frontend JavaScript applications.


Tags: clojure java clojure-vs-java


Copyright © 2024 Jakub Holý
Powered by Cryogen
Theme by KingMob