Hacker News new | ask | show | jobs
by tieTYT 4427 days ago
> When I start using a language, there are usually some situations where I can't understand why my code isn't doing what I expect it to do. When that happens to me in a language like JavaScript, for example, finding out what the problem was is generally a very frustrating experience

This is a very weird paragraph to me because I've experienced the exact opposite. You can see my frustration in this stack overflow question I titled "How do I get better feedback from Clojure errors?": http://stackoverflow.com/questions/16901836/how-do-i-get-bet...

While I agree that JavaScript has tons of "Wat" quirks that shouldn't be there, I rarely run into them. And more importantly, when I get errors in JavaScript, the cause is relatively easy to track down.

With Clojure on the other hand, it is really difficult for me to figure out why I'm getting the error. Yes, I get the error because I "was doing it wrong", but the errors don't help me figure out what I was doing wrong.

-------------

> With Clojure your editor (be it Vim, Emacs, Light Table...) is permanently connected to a live REPL. You continually develop, test and modify functions with subsecond feedback. Continuously. All the cores in your brain are lit, as you have literally no time to think about anything else. That's not only deeply satisfying, but also leads you to certain thought paths that slow feedback and its inevitable lower focus would have simply blocked. That's one of my favorite parts of Clojure.

This is very useful when you're writing new code, but I found myself scratching my head when I had to go back and modify already existing code to add a feature. As a workflow, I don't "get" when/how you're supposed to add automated tests when you're using REPL driven development. But, once I went back to my code, I always wished they were there.

You see, I'd modify the code and break something and then the problem I described above made fixing it very time consuming. Usually the cause of my problem was my simple functions wouldn't integrate together the way I expected. The REPL gave me the quick feedback to say that "increment-number" worked, but I would accidentally pass in a String or a vector into the function.

2 comments

I have been working in both clojure and javascript for a while. When I encounter bugs in javascript assuming it does not crash, it can become difficult to track down the source due to the lack of name-spacing, mutability of variables that allow for race conditions, and unintended changes upstream if you're not careful.

Where as in clojure, the scope of name spaces is generally smaller, while the errors are more cryptic, I agree. The line number that it points you to and use of the repl allows one to dissect the function in great detail and by checking the incoming data and outgoing data, the bug becomes much clear. At least in my experience.

shrug Just different experiences I guess. I should note this isn't exactly an apples to apples comparison. I am using a lot of discipline in my JS project. I'm writing the code test-first most of the time, and I only have one global variable in the whole project.
Some JS frameworks lend to more difficult debugging.
I've done a lot of Clojure. For iterative/REPL-driven development I find Haskell a lot more pleasant. The types drive how I think, provide way-way-way better feedback on mistakes, and provide a new modality for querying my code in the REPL.

As a bonus, the UX to ghci is better than using nrepl/cider in Emacs. Reload "just works" and works more quickly than reloading namespaces in Clojure. I was gobsmacked when I saw how much better ":r" worked in ghci than reloading in the Clojure REPL.