Editors and IDEs for Clojure

June 15, 2013 —

Since starting at my new day job almost two months ago, I've been writing Clojure (and Javascript... working on web apps) almost exclusively. Right off the get-go, I began using Eclipse with the Counterclockwise plugin. This was at the immediate suggestion of a co-worker, and my being new to Clojure, didn't give it too much of a second thought beyond my initial obligatory "Eclipse? ew!" reaction.

Of course, most people who use Eclipse for an extended period of time will start groaning about it. It's slow, it's bloated, it's menu's/configuration is a mess, it likes to randomly corrupt the workspace, you can't really theme it that well (especially if you like dark themes ... damn those scrollbars!) ... etc, etc. I've always been much more comfortable within a fairly full featured IDE as opposed to a simple text editor for large projects. I suppose I get that from spending most of my professional coding time within Visual Studio over the last 8 or so years. For statically typed languages like C# and Java, IDEs offer a lot of great functionality so I don't feel too bad about that.

Most of the refactoring features in Eclipse aren't available to Clojure projects (yet?). Autocomplete and some other intellisense features work, but for calling into Java code from Clojure (which is where I think it would be most useful), it kind of breaks down to the point of being somewhat useless, if it works at all. Debugging works well, but to be perfectly honest, I find it more useful to isolate functions in the REPL to test issues with individual bits of code.

Ahh.. the REPL. How this has changed my coding workflow, let me count thee ways. I never knew a REPL could be so great. Being able to, in the same source file, send bits of code to be evaluated instantly to test work-in-progress stuff is amazing and cannot be overstated. Having a REPL connected to a running application is incredibly useful for debugging purposes as well. I think in the past two months I've run Clojure code through the debugger in Eclipse once (though this could likely change as I use it more and more and get into even larger projects). I just tend to prefer relying on the REPL, or even using println-style debugging as needed, which isn't that often. e.g. spitting out the value of something in a user's session which you can't really get from a REPL easily. For someone new to Clojure (and functional programming in general), the REPL is a godsend. Not sure how a function works? I can write some quick code and test it immediately. No need to start up a new test project or open a new source file or whatever else to fiddle with little bits of code to help myself understand how some bit of Clojure works.

Anyway, back on topic ...

I basically feel like Eclipse is very much overkill. For Java code, I much prefer to use IntelliJ anyway, so I see little benefit to continuing to use Eclipse if there are better options. However, there aren't a hell of a lot of better options as it turns out!

IntelliJ's La Clojure isn't very actively developed it seems, almost like there's only one person at JetBrains developing it as a side-project. It's unfortunately missing a couple important editing features still, most notably the "expand selection" feature in Counterclockwise which almost feels like a requirement now that I've become so used to it. Although I did find that I preferred La Clojure's autocomplete and intellisense functionality to Eclipse's. Especially for calling back to Java code, it seemed quite mature in that department.

Light Table is quite interesting, and I'll be following it waiting for any new updates. It supports a nice set of web languages, including Clojure, and is at a mostly good point right now feature-set wise, but it's still missing some niceties that prevent me from using it as a daily editor. Again, it's missing Counterclockwise's "expand selection" feature. It's editor customization settings are also a bit lacking, but apparently v5.x will bring with it more support in this area. Light Table is really worth at least a quick look. It's support for spitting out results of evaluating code inline in the source editor is quite amazing and is really worth trying out even if you never intend to use the editor again (see here for a very quick and simple example where it shows the results of evaluating code I just typed up in a new file). I don't know of any other editor that does anything like this. It actually pains me that I can't use this editor day-to-day right now due to it's other missing features. I really want to use this all the time. Arrggh! Hopefully soon!

Sublime Text 2 has some Clojure and REPL support that can be patched together from different plugins. It could probably be made to work well enough, but after watching a video of someone demoing it, I was left feeling like that it might not be the best option currently (again, seemed to be missing features, other things half-working, etc).

Which brings me to Emacs. A lot of people who write Clojure seem to recommend Emacs first, and then Eclipse + Counterclockwise for the non-Emacs users and then pretty much stop there. But they all seem to recommend at least giving Emacs an honest try first. Emacs is, obviously, very Lisp friendly, and that support apparently extends quite nicely to Clojure. There are at least a couple different guides out there for getting started.

So, following in the steps of taking a job writing Clojure code and in the spirit of trying new things out I will force myself to use Emacs for the next couple weeks. Who knows ... maybe I'll be pleasantly surprised! Assuming I decide to stick with it and don't throw it away in absolute disgust, I intend to document whatever Emacs setup I end up with here, mostly as a reference for myself, but maybe it will be useful for someone else learning it.