Friday, January 13, 2012

Is this a good introduction to Clojure?


So I wanted to help someone get started with Clojure today. For those who haven't done much with Java before, the incredible overhead associated with doing the most trivial tasks leads to a bad impression.

To make matters worse, I was trying to set up Emacs for use with Clojure. I'm not an Emacs noob. I used ESS as my main development environment several years ago, but was not impressed, and moved on.

[Edit: Used bold font to emphasize that I'm writing from the perspective of someone who decided he'd try Clojure using Emacs. My personal recommendation is to use Counterclockwise or Clooj.]

This is what someone new to Clojure would experience.

Go to the main Clojure page instructions.

"Install clojure-mode."

Don't know what that means, but I'll click the link.

"If you use package.el, you can install with M-x package-install clojure-mode. Otherwise you can do a manual install by downloading clojure-mode.el and placing it in the ~/.emacs.d/ directory, creating it if it doesn't exist. Then add this to the file ~/.emacs.d/init.el:"

Well, not being a total Emacs noob, I tried M-x package-install clojure mode.  I got [No Match] in return.

What is clojure-mode.el? Where do I download it? Google found it for me. I downloaded it to the ~/.emacs.d directory. I added the lines to init.el (though I had to create that file, something the instructions didn't mention).

The vast majority of new Clojure users would have given up by now. Users should not have to figure things out for themselves - that is the purpose of documentation.

So let's move on. There's a discussion of how to set up package.el. Okay, that doesn't apply to me.

Then there's a discussion of clojure-test-mode. It says "This source repository also includes clojure-test-mode.el, which provides support for running Clojure tests (using the clojure.test framework) via SLIME and seeing feedback in the test buffer about which tests failed or errored. The installation instructions above should work for clojure-test-mode as well."

So do I need it? Is it something that most users install? I'm going to skip it. I can do tests when I get to that point.

Then there's something about paredit, which I hate, but it's recommended for all users.

Following that, there's a section titled "Basic REPL", which says, "
Use M-x run-lisp to open a simple REPL subprocess using Leiningen. Once that has opened, you can use C-c C-r to evaluate the region or C-c C-l to load the whole file.
If you don't use Leiningen, you can set inferior-lisp-program to a different REPL command"

The only way you'd have any idea what that means is if you knew beforehand. That may have set a record for the least informative paragraph ever written. I get tired when I read something like that. What is meant by "different REPL command"? Heck with it, I'm returning to the main page. {Note: this is explained on the main page, but the reader isn't told that.}


I created a new clojure file in Emacs (ending with .clj). There's no automatic indentation! How on earth do you write Lisp code without automatic indentation?

Eventually I got it sort of working, though I never got Clojure 1.3.0 to work. This is not a pretty introduction to Clojure. {I'm not saying it's my introduction to Clojure. It is the introduction to Clojure for anyone who reads Emacs + Clojure is the best alternative.} There's a lot of room for improvement.

I recommend immediately eliminating all references to Emacs when talking about Clojure, with an exception for "Don't waste your time with Emacs if you want to learn Clojure."

12 comments:

Anonymous said...

At the clojure-mode page there is a section on how to configure package.el. It's called "setting up package.el". It's two lines down from the section you mention. Perhaps it should be more prominent/better written, but I'm pretty sure things would have worked if you'd done what it says.

lmf said...

Thanks for the comment, but I did mention that section in my post. If package.el is necessary or preferred that should be stated clearly on the page.

It's never good to give multiple options without some background on how to choose.

George said...

I agree that those instructions aren't very good. The best instructions actually are in the comments below that article (and they're quite good incidentally).

Despite the instructions, as a Clojure beginner myself I still absolutely recommend Emacs even for beginners. Just download the latest version of everything and you'll be OK.

If that's still not your cup of tea I've heard good things about Clooj, and the Counterclockwise plugin for Eclipse as well.

The easiest way of all would be to just get Leiningen and use a command line REPL, but to be productive in that environment probably would take as much effort as using Emacs.

Simon Hawkin said...

I agree that the initial setup instructions are lacking.

I disagree that mentioning emacs should be avoided. Emacs is a rich environment used by many clojurians. After emacs has been set up using it with clojure is a great pleasure. Yes, the first setup is a headache. The pain should be alleviated, not the head cut.

Christoph Seufert said...

first you should laern to read: The sentence said "if you use package.el"... And dont blame clojure for you beeing a newbie to Emacs.

Vijay Kiran said...

I recommend immediately eliminating all references to Emacs when talking about Clojure, with an exception for "Don't waste your time with Emacs if you want to learn Clojure."

But the the getting started page you linked to does say "Getting Started with Emacs". If a user don't want to use Emacs, aren't the other pages like Getting Started with "Clooj/TextMate/Vim/Netbeans/Eclipse/IntelliJ" more relevant ?

lmf said...

@Simon @Vijay

My issue is with the recommendation given in so many places that Emacs + Clojure is the best choice. That's terrible advice. First impressions are important.

Counterclockwise does a great job for me, and installation is dead simple.

Anonymous said...

Emacs + Clojure is a great option if you're already an experienced Emacs user. This is not meant as an introduction to Clojure, but as instructions for such an user.

Emacs definitely has a steep learning curve though, so it's true that it should be recommended not to try and learn Clojure and Emacs at the same time. (It might work with a starter pack that contains an already set up Emacs installation for Clojure, and a book that contains step-by-step instructions, as it did for me with Practical Common Lisp, but it doesn't with what is available now.)

Anonymous said...
This comment has been removed by a blog administrator.
Simon Hawkin said...

@lmf: Emacs + Clojure may be the best choice for those who are familiar with Emacs and are learning Clojure. Learning "Emacs + Clojure" is certainly much more work than just learning Clojure.

Unknown said...

I used Emacs 20 years ago. When I came to Clojure, I came from a Java and dynamic scripting languages on the JVM background - so I naturally went with Counter Clockwise in Eclipse because I'd been using Eclipse for years. In late October I switched (back) to Emacs and I'm very glad I did - once you get used to the keyboard shortcuts, it's far and away the best development environment for Clojure...

That said, there are far too many words in all the Emacs / Clojure tutorials out there. The basics are actually really easy - I've set up Emacs / Clojure on Mac, Windows and Ubuntu - but there are horrible gotchas on each platform. I started writing new installation notes but various warned me that adding to the pot may only make things worse :(

Anonymous said...

Not only is it hard to get Clojure/Emacs up and running, but it's incredibly difficult to customize and update. I'm stuck running the same set-up I used when I started a couple of years ago, because every time I try to update to a new emacs/swank/lein/etc. it just breaks everything horribly.