Hacker News new | ask | show | jobs
by lukev 4750 days ago
Most Clojureists write code they want to keep in their source file, and then evaluate it by using their editors tooling to send it to the REPL from there. I usually just type things into the REPL for one-off exploration or experimentation.

What editor are you using? Emacs certainly has had the most mindshare so far, but it's a beast to get started with. I recommend CounterClockwise for non-emacs folks: it's got all the features you need to be effective, and has full integration with Leiningen.

As far as errors and error messages; yeah, it's hard, and a lot if it is just getting experience. But one thing that will really help you out is to write your program in very small chunks, and test each part as you go. That way, when something goes wrong, you'll have a very good idea about where to start looking.

1 comments

Yeah I'm using CCW right now. I like it, but it's annoying that the repl doesn't start with (doc) or (source). I read an article from Stuart Sierra where you can add your own user.clj to the classpath and put code in it to load those up on start, but I haven't tested if CCW's repl will use this correctly. Assuming it does, tips like this are essential and should be in the book IMO.

Your last paragraph is good advice, but IMO I code like that in general. Consider this code:

(-> x doSomething1 doSomething2 doSomething3)

This was tested as I went, but after the fact, I had to change x. Now any part of the whole series of steps could be broken. This is where I spend 15 minutes trying to understand what the error message means. shrug Maybe this is just what's expected when you're new to clojure.

The best advice I can give there is, learn how to read a stacktrace. I won't lie, they're messy, but they do contain the information you need to figure out that sort of problem.

For example, all Clojure function calls have the same sort of appearance in the stacktrace, which you'll learn to recognize. You'll be able to pick out "doSomething2" in the trace, which will then help you narrow in on the problem. Recurse through the stack trace using this technique until you find the specific form which is the problem.

Just added a "reading stacktraces" idea to the book: https://github.com/clojure-cookbook/clojure-cookbook/issues/...

Yeah, I tend to put a `pprint` at various points in the pipeline. (One which returns the form unchanged.)

I use print statements with virtually any programming language, basically using binary search to locate where my assumptions are violated.