Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clojure debugging

How does one debug clojure? Is there an similar tool like Eclipse debugger for java, or do I have to go poor man's solution and use REPL and print statements to trace bugs?

If latter, I'm skeptical if the benefits of functional paradigm tops the primitive/lack of tooling? After all, what makes Java so good is not the language, but the excellent tooling to aid the coding, refactoring and debugging. Only the fact that clojure shows obscure java stack trace instead of translated error messages to spot the problem puts me on toes.

I can't help but get impression that clojure ecosystem is incomplete, and using it in production would know more troubles than benefits. Imagine a newcomer debugging a bug from clojure someone else has written, without proper tooling to step in the code.

I really want to learn this language and hope my impressions are wrong. By syntax wise, the language feels comfortable due it's simplicity and uniformity.

like image 504
Tuomas Toivonen Avatar asked Apr 29 '17 07:04

Tuomas Toivonen


2 Answers

I use the awesome debugger found in cider (emacs), and I heard that cursive (intellij) has a very nice debugger as well.

Personally, I find clojure no less then great for production code. I can connect with the debugger to a production process (if its needed), debug and redefine things to have quick fixes without ever taking the process down or reloading. I find the tooling wonderful, emacs is insanely powerful and you have refactoring (if you really need it, i hardly ever use it in clojure as opposed to java) and almost anything else you need. Even stack traces are shown very well using cider.

For me, right now, the thought of writing production code in java gives nightmares.. :)

like image 82
Shlomi Avatar answered Oct 28 '22 09:10

Shlomi


emacs has debugging, IntelliJ+Cursive has debugging, Eclipse, and others. A google search for any of these will yield more information. I use intelliJ and its debugger is full featured and nice, allowing you to put breakpoints even in clojure and java core code.

Initially I used a debugger with clojure, and every few months I pull it out when the problem seems to warrant it. But debuggers are not all they are cracked up to be. For example, when dealing with async code, a debugger is not very helpful. REPL-driven (and test-driven) development is a big advantage over the traditional "compile and run" process that a language like java requires, and almost eliminates the need for a debugger.

Clojure stack traces are just java stack traces, with clojure code mixed in. If a java stack trace doesn't make your eyes bleed, a clojure one shouldn't be much worse. The problem with stack traces seems to be that people don't actually read them.

I would disagree with your comments about Java; Java has many positives, first and foremost its ubiquity resulting from "write once, run anywhere," some very good core libraries, and more. But refactoring and debugging are (almost) completely unrelated to the language itself. And I'd say Clojure's tooling is pretty simple. Dependencies are handled easily. In short, you don't choose a language because of a debugger, though the editors/IDEs mentioned above have some good ones available.

We run clojure on huge, major production systems that span the world, and many other companies do too. The java ecosystem provides a particularly well suited host for clojure for critical systems.

Imagine a newcomer debugging a bug from clojure someone else has written...

A newcomer learning clojure and debugging some code may in certain situations want to use one of the debuggers mentioned above, but in most cases he or she will be better served by understanding what's going on first, developing a closer familiarity with clojure, and only then resorting to a debugger.

like image 26
Josh Avatar answered Oct 28 '22 08:10

Josh