Hacker News new | past | comments | ask | show | jobs | submit login
Real world Clojure (puredanger.com)
97 points by puredanger on Oct 20, 2011 | hide | past | favorite | 34 comments



I saw he mentioned switching to Emacs. Is the emacs - clojure workflow really as good as it's made out to be, as in good enough to both switching from Vim? I was planning on getting into Clojure this weekend, and if it's actually worth doing I suppose I could learn Emacs at the same time, but I've always been turned off by the weird key chords.


The last time I used it, SLIME integration for Clojure was very slick. It was a while back so there were a fair number of moving parts to align, but I'd guess that has gotten better.

It is worth doing, especially if you've never used another integrated Lisp environment, but I wouldn't recommend laying it on top of learning Clojure. I'd say learn Clojure first, then try out emacs and the emacs integration.


Slime and Clojure have improved, mainly through clojure-jack-in and ritz. Of course the Common Lisp Slime experience is still better but the essentials are definitely there with Clojure.

There are several heavyweights in the Clojure community that use VIM and have developed good plugins, and Rich never seems to be using SLIME during presentations, so you can definitely get by fine without it.


Agreed. There are many ways to fly. I'd say Emacs is well-developed and probably the most common, but certainly not the only choice.


I agree. Emacs is a power tool for writing Clojure. I learned Clojure first with tools I knew, then learned Emacs later. For me, that was a much better way to deal with the cognitive load.


I find emacs + swank to be roughly equivalent to vim + vimclojure + paredit.vim. Install vimclojure and the lein-nailgun leiningen plugin and you'll be up and running in no time.


Yes it can be really good. You can have compilation on the fly, integrated REPL, completion, some debugging facilities, edition of s-expression at the structural level etc.

See this video for an overtuned (!) Emacs https://github.com/overtone/live-coding-emacs

The configuration can be found here: https://github.com/overtone/live-coding-emacs


Thanks, beautiful stuff. (The music more than the editing facilities, though those were nice too.)


I'm also a big Vim guy and recently spent a few late nights hacking on some Clojure stuff. I tried to learn both Emacs and Clojure and eventually had to give up and just use Vim until I was more comfortable in Clojure.

At minimum, you need a easy way to paste top-level forms into a repl. This is the simplest way for Vim: http://www.vim.org/scripts/script.php?script_id=3023 That script is actually crazy useful & I now use it for a whole bunch of different use cases.

That said, the Emacs->Slime<->Swank<-Clojure bridge is really much better & think that I'm going to invest some more effort into becoming proficient at Emacs. My limited experiments with Slime were very positive & nothing in the Vim world even comes close. I tried all the various attempts in their current form as of two weeks ago. Most are hard to get running, don't work exactly right, struggle with subprocesses management, etc. And you're totally on your own with those, no warrantee and no maturity.


I recently saw this mentioned in a post : http://www.google.fr/search?q=slimv

might be better


Yup, tried that one. Had a hell of a time getting it to work. Once it did work, it just didn't feel right. I realize that's very subjective, but it matters.


I use SLIMV, but for Common Lisp. It works quite well most the time, and with fewer keystrokes than SLIME.


I'm trying out emacs with evil mode (vim emulation) and it's been quite nice so far.

Pretty good clojure and coffeescript modes.


A well-tuned Emacs/Clojure environment can be very very smooth. Mine is not particularly well-tuned - I tend to get tired of tool config'ing and just put up with stuff so I can get work done. :)


If you're on a mac I have a good blog post which shows how to setup aquamacs for clojure.

http://jaydonnell.com/blog/2011/10/07/setting-up-aquamacs-fo...

The steps are pretty much the same for regular emacs, you just need to put things in ~/.emacs.d/ instead of ~/Library/Preferences/Aquamacs\ Emacs/


While Aquamacs is a viable choice, from what I understand Aquamacs is not fully compatible with the Gnu Emacs settings and I was advised by people I trust that Emacs.app was a safer bet. I tried Aquamacs anyways but can't say I liked it very much. Emacs.app with @technomancy's Emacs starter kit made things pretty easy.


I also tried Emacs.app and Aquamacs. Aquamac's behavior was totally odd & didn't match any of the documentation. I found the Cocca Emacs.app to be much easier to set up and get running. That said, neither of them feel as good as MacVim, as far as native Mac apps go.


I used the following version of Emacs back when I had a Mac.

http://emacsformacosx.com/


How so?


Lots of little things.

The one that drives me really crazy is that on Lion, both Emacs freak out if you try to resize from from anywhere except the bottom right corner. Similar issues with the green (+) button; full screen mode, etc.

Also, since you'll probably remap cmd to meta, you lose some system shortcuts which can be convenient when switching back and forth between various apps and your brain can't keep all the shortcuts straight.


those don't seem specific to aquamacs. I also don't remap cmd to meta, i bind the most common things to cmd like this.

(global-set-key (kbd "A-j") 'find-file)


I was referring to "neither of them feel as good as MacVim" - in particular with the Lion resize issues


I'm not sure what the value of emacs purity is. I've used both, and I like aquatics better. Either way, the setup for clojure is effectively the same.


For one thing, if you work on other platforms you might want Emacs to behave the same way on all of them.


It would be interesting to see an explicit example of

"In the area of query planning and optimization, I found that at some point I hit a wall with what I could do in Java. There was latent abstraction that I understood but could not express in the code."


Unfortunately, this is one of things that I have found very challenging to convey due to the scope of the code base.


"I don’t find that using Clojure making the overall process of writing new code faster. My thinking/typing ratio is much higher though. I think the reason is that I have a huge confidence in Java refactoring tools and my abilities to morph the code towards where it should go. In Clojure, if you start writing code there is no ceremony and within two minutes you realize that your first idea was dumb and your data structure should be totally different and it drives you back into the thinking phase."

I'm not sure that convinces me to try Clojure. To me less typing is great, but only if it still makes sense and I don't have to come at it a few ways before I get it right. That is probably why I never took to Perl. It just looks like garbage and I couldn't get past that.


> I don’t find that using Clojure making the overall process > of writing new code faster

He's talking specifically about writing _new_ code. I think the implication here is that Clojure encourages more consideration up-front, resulting in designs that are easier to modify down the road.

Given how much time is spent maintaining code vs writing new code this seems like a reasonable trade-off.


I find that with a REPL in hand, I tend to play with functions while letting my mind almost drop into the problem space.

So I do less up-front design, but wind-up with somewhat better code at the end.

The other weird effect is that I find that this helps me think better about coding in something like C as well. A little experimentation at the REPL helps me understand pieces of the solution better.


I think part of it is that you have a higher reimplementation rate for your code in languages like Clojure. If something takes you 3 hours in Java and you find its a crap design, you might take 15-30 minutes to figure that out in Clojure.

It has the side-effect of teaching you to think through your ideas more (wait, I thought we were supposed to avoid side effects! ;) )


Rich Hickey's "Hammock-driven development" keynote seems applicable here:

http://blip.tv/clojure/hammock-driven-development-4475586


I think the point is that less ceremony makes it feel like less progress is being made, but actually it's equivalent. Information density is much higher compared to java, but the programmer is still rate-limited himself, so his brain will work at the same rate. The benefit would show up in time spent reading and in higher signal/noise as you don't have to spend brain cycles dismissing boilerplate. It's not as big a boost as say garbage collection vs no garbage collection, but still notable. I think clojure's immutability story reduces cognitive load quite a bit on its own. Also, I don't think clojure has the craziness of perl, but I've never used perl. It's pretty easy to read, IMO.


Lol! For the first time ever I ran across a reasonably sized perl based project where I actually understood and could read the flow of things and I've written plenty of perl many ages ago. (even that god awful object oriented style perl they made me use at bellatlantic for "Watson" )

Never had any issues playing around with or reading others emacs lisp macros though. After the initial within within brain fuck part is over at least.


I hope that you wouldn't try Clojure because it features less typing. That's not the point, merely an observation. The reason to try Clojure is that it allows you to easily create powerful abstractions that are not intertwined. You get less typing as a bonus. :)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: