Tools for Learning Clojure, Part III: Nightcode

Tools for Learning Clojure, Part III: Nightcode

In Part I, I talked about Clojure and the need for a convenient “REPL”: a piece of software that lets you type input at the language engine and see its responses. In Part II I talked about Leiningen, a very cool tool that not only gives you a good REPL but also automates many other tedious aspects of development. (I find myself wishing very strongly that TCL, my usual language, had something like it.)

So at the end of Part II, it looked like I had a solution: Leiningen gives me the REPL and I can use any editor I happen to like. But wait! All is not rainbows and unicorns. At home I use a Mac; but at work I use a Windows machine. I’m looking for a solution that works well on both platforms.

When working with a REPL, I often find myself fixing bugs and making other changes in the editor and then pasting them into the REPL. This works great on the Mac. I can use any editor I like, and easily paste my edits into a Leiningen REPL running in a Terminal window. It’s not ideal—I’d like better integration between the editor and the REPL—but it’s workable.

Not so on Windows.

Leiningen is a command-line tool; and on Windows it’s accessed via a batch file designed to run in a normal Windows “command shell”—what we used to call a DOS window. This leads to two problems. First, on Windows I use an environment called MinGW which gives me a terminal window with a UNIX-like “bash” shell. The UNIX programming environment is a delightful place to work, and I’ve been using it on one platform or another for decades (including the Mac—OS X is UNIX underneath). Using MinGW also happens to be the easiest way to perform some of the development tasks we need to perform on Windows.

Unfortunately, the Leiningen “lein.bat” file doesn’t work properly when executed in a bash environment. In order to use it, I need to pop up a Windows command shell window in addition to my usual bash shell window.

The second problem is that pasting text into a command shell window is too annoying for words. Those of you of a certain age will remember running DOS programs like WordStar and WordPerfect and Lotus 123. The command shell window is designed to let you run old programs like that; and since those programs expect to handle the standard Control-X, Control-V and Control-C keys themselves, you can’t use them to paste text into the command-line. Instead, you have to select a menu item of a submenu of the window menu, which gets old really fast. Copying text out of the command shell is equally annoying.

Once I realized this, I went looking for the next killer Clojure app: a simple “IDE” (Integrated Development Environment) that supports Leiningen directly. There are a number of these; both Eclipse and IntelliJ (two of the most popular Java IDEs) have Clojure plugins, for example. But these tools aren’t simple; they are more of a way of life, and all I’m wanting to do at the moment is play with Clojure.

And then I tried Nightcode. Here’s a picture (click on it to see it larger):

I’d glanced at Nightcode earlier, and had passed over it. It looked a little clunky: lots of buttons, no pretty icons, no proper menus. And when I tried it, I discovered that it is a little clunky; but it works and works well. First of all, it supports Leiningen natively. It can create new project trees, and it can work with project trees created using Leiningen from the command line. It has a built-in REPL (two, in fact) that works quite nicely, and a syntax-highlighting editor that’s just capable enough to keep me from going nuts.

Looking at the picture above, you can see four areas. In the upper left is the project workspace. Here’s where you view your project tree; to edit a file, click on it in the project tree. In the upper right is the editor. In the lower right is an all-purpose pane that’s used to display information to the user; it is also the main REPL window. In other words, I can be looking at the code in the editor, and calling it interactively in the REPL, all in one place. The buttons at the top of the scrolling pane allow you to run your program, compile it and run it in as a REPL, build it, and so forth.

The lower left is another REPL; it might be attached to the instance of Clojure in which Nightcode is running, I’m not sure. I mostly use it to see if some function name I want to use is going to shadow one of the built-in functions.

I picked up Nightcode a couple of weeks ago, and spent most of that day working on some Clojure code in it. It was a fun, remarkably pleasant experience; and I’m still happy with it a couple of weeks later.

Nightcode isn’t the ultimate Clojure programming environment; if I were using it all day every day for production work I’d want something beefier. For casual use, though, it’s easy to use, easy to get started with, and doesn’t try to take over your life.

Recommended.


Browse Our Archives