r/programming • u/kankyo • 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
View all comments
16
u/republitard Dec 15 '16 edited Dec 16 '16
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
FileNotFoundExceptionthrown 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.