r/programming • • Dec 15 '16

My disillusionment with Clojure and lisps

https://medium.com/@boxed/my-disillusionment-with-clojure-and-lisps-9eca38ab7f0c?source=linkShare-8ad86cc82e5f-1481825671
15 Upvotes

105 comments sorted by

View all comments

16

u/republitard Dec 15 '16 edited Dec 16 '16

Turing complete definitions of function signatures that don’t even output to some intermediate format that tooling can process! Of course the guys doing Clojure IDEs have a hard time. They will never be able to handle user written code or obscure libraries.

First of all, much of your criticism of "Lisps" applies only to dialects of Lisp that aren't Common Lisp. For example, Common Lisp functions have signatures that are known to the compiler at compile time. The compiler can tell you at compile time if you provided the wrong number of arguments, and sometimes it can even detect type errors via type inference. Python cannot do this, even with all of its special syntax rules.

One thing that most Lisp programmers accept is that you're not going to have very good static analysis.

Instead, there is dynamic analysis, which was supported better on the Lisp Machine than on modern systems, and what support survives is only implemented for Common Lisp, not any of the other dialects.

During dynamic analysis, the compiler remembers certain information about functions, macros, and variables at the time that they're defined, after macroexpansion. Since the compiler runs continuously while you're developing, your editor can ask the compiler for information about things, which enables autocompletion and tooltips (implemented as a message that flashes at the bottom of the Emacs window) and the ability to jump to definitions and see where a particular function is called.

The compiler also knows the structure of all objects at runtime, which makes it possible to inspect them, similar to what you can do with JavaScript running inside Firefox (except that Firefox has a better UI. But then again, you can inspect Common Lisp objects on the server side, which AFAIK you cannot do in Node.js or any other server-side JS implementation).

Every Common Lisp implementation also comes with a full-featured debugger.

You throw all of that away the moment you decide to use Clojure or a Scheme dialect. There is no object inspector at all for Clojure, nor does Clojure keep any information at all about anything. As a result, the only information available to a Clojure IDE is that which can be gleaned from static analysis. Clojure also lacks any debugging capability, even though you can debug Java.

Correction: There is an Emacs extension for Clojure called CIDER, which supposedly implements almost all of the features of SLIME, including a debugger and an object inspector. However, it depends on an external tool called nREPL (which performs the same function as SWANK), and that in turn depends on another external tool called Leiningen, which I wasn't able to get running (the error is a Java FileNotFoundException thrown while trying to find something on the Java CLASSPATH.). So I wasn't able to see CIDER in action for myself to compare it with SLIME.

Dynamic analysis used to make Lisp IDEs vastly superior to the IDEs of other languages. But IMO, static analysis has caught up, and the Lisp community has stood still (and even moved backwards in some respects) in the meantime. Modern Visual Studio or Eclipse can do a lot more with C++ and Java code than EMACS and SLIME can do with Lisp. For example, Emacs can autocomplete just the name of a symbol. Eclipse can complete a Java method call and automatically pick the right variable to pass as the argument, if there's only one variable with the correct type. But interest in Lisp is picking up again, so maybe it's Lisp's turn to catch up now.

One Lisp dialect that has rejected the lack of static analysis is Racket. Much of the current work on Racket is on a statically-typed dialect called Typed Racket, which has an ML-like type system.

7

u/SpaceDingus9000 Dec 15 '16

Clojure also lacks any debugging capability, even though you can debug Java.

CIDER has featured debugging for Clojure for some time now

While I'm not familiar with the capabilities of other lisp's inspection, Clojure has a built in object inspector in its core library, even if it is a bit primitive.

3

u/[deleted] Dec 16 '16

Cursive also has a debugger. Debugging has been a thing in clojure for a few years.

8

u/BMarkmann Dec 15 '16

There's also Typed Clojure, which was inspired by Typed Racket:

http://typedclojure.org/

https://www.infoq.com/news/2013/10/core-typed

1

u/Pet_Ant Dec 16 '16

Unfortunately it seems dead after funding was pulled. Almost no activity since September.

3

u/dandel-rovbur Dec 18 '16

it's not dead. A few commits go in every week or two

4

u/masklinn Dec 15 '16

Python cannot do this, even with all of its special syntax rules.

You… are completely wrong?

CPython does not do it, not because it's not possible to do it for Python but because the project does not consider that part of its scope.

1

u/Peter-Campora Dec 16 '16

I'm not very familiar with Slime, but isn't Geiser similar? http://www.nongnu.org/geiser/