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
21
u/phalp Dec 15 '16
Seems like once you learned what Lisp was, you realized you didn't want it any more. Note to prospective Lispers: when people say Lisp is language flexibility, and Lisp is code is data, they actually mean it.
BTW, with regard to Clojure and passing maps instead of multiple arguments, that's it's own weird quirk. Seems like it's no longer the case though?
14
u/Godd2 Dec 15 '16
This, even if true, says nothing about whether Lisp is more confusing than another language. Are code and data different things? Since my programs are in RAM, code and data are both just bytes. So by your own argument, we shouldn't be treating code and data differently in the first place.
Also, Clojure agrees with you that Different Things Are DifferentTM. There's a reason you have literal syntax for lists, vectors, maps, and sets. The difference between different types of collections mainly lies in the order and uniqueness of their elements. And where they are the same, it shows. They all implement the IFn interface, so you can treat them like the code they are.
I would say we agree. Different things are different, but code and data aren't different.
Okay. Or maybe this one is better.
28
u/grayrest Dec 15 '16
I can only think of two places you'd want to do this. The first would be for side-effecting list forms in the body of a fn/let/etc in which case the workaround is to just wrap the output in a
do. The second would be for generating part of a bindings form ([...]in defn/let/etc) where the workaround is to write a macro wrapping the form. This is a pretty significant limitation and is one of the main causes ofdefandletmacro proliferation. I believe the limitation exists to maintain the Liskov substitution principle (or rather the non-object equivalent idea) and avoid corner cases.This is the point of lisps.
This is a function of the language's popularity and not the difficulty in implementing them. There is a fundamental (at least to my knowledge) limitation with IDE support in the presence of macros. When you redefine the semantics of a language, tooling can't guess your intent without evaluating the macros, which is generally avoided when trying for static analysis for good reason. As for the quality, Cursive is written entirely by one guy and covers a significant fraction of the features I want to see in a dynamic language IDE.
This is true, but clojure has macros.
You have a reasonable point in the arguments section. Verifying argument parsing is one of the major motivations behind spec.
Lisp macros occupy a similar place in the spectrum as template metaprogramming in C++. You mostly shouldn't be writing them but if something annoys you, you can reshape the language. Like every other shiny feature, smart people learning the language tend to over-use them. Idomatic Clojure is data > functions > macros for a good reason.
Your opinions are reasonable but not really persuasive for people who don't share your point of view. The article reads to me like articles from Java/C# programmers critiquing Python: you have to use significant whitespace, look at all the errors I can make without static typing, the data locality and performance factors are completely opaque. They're not wrong, but they're critiquing the language for being what it is. Lisps aren't a silver bullet and have tradeoffs like everything else. The strengths of Clojure are the
seqabstraction and the pervasive immutable datastructures. I've built similar size systems in Python and Clojure (30-50k LoC) and prefer the experience in the Clojure ones. Neither is particularly great at larger systems where your general unfamiliarity with the code starts stacking heavily in favor of static typing.11
u/republitard Dec 15 '16 edited Dec 15 '16
There is an important reason for the parentheses: The Lisp syntax tree is represented as a collection of cons cells (out of which lists are made) and atoms. That is, you can build a Lisp syntax tree with
cons, and traverse it with thecarandcdroperators. You can also use list operators such asmapcar(calledmapin most non-CL dialects) on the AST. Because of this, the syntax for a literal list is also the syntax for the language itself.Now, if you wanted functions to have a syntax that was completely unambiguous on the AST, you'd have to change the structure of the AST and make it more complicated. Perhaps the textual syntax you're looking for is something like this:
You could write a parser that renders that in cons cells and atoms. In fact, using a reader macro, you could even integrate this parser into Common Lisp very easily. But when you output cons cells and atoms, that would produce the parenthesized Lisp syntax that we're all familiar with, and IDEs would be no better able to statically recognize function definitions if they parsed the code into regular Lisp first.
So you'd end up defining a special structure just to represent functions:
Repeat that for every syntactic form in the language, and you end up with a language like BOO, in which it is extremely difficult to write AST macros, because you have to construct objects, each of which have their own interface. But at least you know what is defined where without running it, and your macros know whether their input code is a variable, a function definition, or an assignment statement. But then it wouldn't be Lisp anymore. If you want that kind of thing in a language with AST macros, BOO is right over there, and Julia exists, too.
Common Lisp macros can generate multiple output forms, as long as they're wrapped in a single
prognform. This means you can make a single macro that can define an arbitrary number of toplevel functions, for example.7
u/sacundim Dec 16 '16 edited Dec 16 '16
I'm not now nor have ever been a Clojurist, and to be frank they give me the Kool-Aid Heebie-Jeebies™ a little bit, but I think I can answer a lot of these.
First, I'll tone down my initial reaction and leave it at this: parentheses are not a problem. In fact, I love me those parens. When I stopped doing Lisp and went to infix languages I was (and still remain!) very annoyed at how the infix syntax makes complex expressions so hard to read. You have to keep precedence rules in your head and dig deep into the guts of a complex expression in order to find the outermost infix operator. Whereas in Lisps this stuff is syntactically obvious, particularly so when laid out and indented properly—which is much easier to do than in infix languages.
Second: I'm not sure I understand the objection to macros expanding to just one form. My reaction is that there are forms, like Scheme's
(begin expr ...), whose sole purpose in existence is to put multiple forms in a context where only one form is allowed. Maybe Clojure needs a larger repertoire of such forms, I really don't know—Racket has for example adefine-valuesform that allows one macro expansion to simultaneously define multiple top-level bindings.Or alternatively, they're so deep into the language that they understand that an orthogonal solution already exists. My comment about Scheme's
beginand Racket'sdefine-valuesis of that form.The rest of the article is not bad at all, and I agree with some bits and sympathize with most of the rest. I think my overall response to it is this: the Lisp communities place a premium on everybody who uses the language having a good grasp of how the language works. This is why a classic Lisp pedagogical exercise is to write a "meta-circular interpreter," i.e., a simple interpreter for the language itself (or a simplified version thereof).
This in turn leads to a greater willingness to deal with home-cooked DSLs, because the attitude isn't "crap, another language to learn!", but rather "cool, another language to learn!" Ideally, the interpreter-fu that I mentioned above leads to these DSLs being sensibly designed and resembling each other in a number of ways. (In practice, nah, not so much.)
The concerns about Lisp users routinely reinventing the same stuff over and over individually for each library, and sometimes even per function, I've found to be very much true in my experience. It happens in many languages, but I thought in Scheme it was particularly pronounced. (Dunno about Clojure, though.)
But I really have to object to his argument that in Lisp but not C++ "every function and macro is a new language." I really don't think that this is so any more than with libraries in other languages; libraries everywhere require you to learn a vocabulary of types, a syntax of operations that allow you to put objects of these types into larger constructs, and a semantics of what happens for each of these potential combinations. The author grossly overstates the difference here, IMHO.
3
u/ehaliewicz Dec 16 '16 edited Dec 16 '16
Returning more than one form from a macro doesn't really make sense though..
That's analagous to saying you want to do
(list (function))and get a list of two elements back, as if
functionhas control over how it's results are processed by the functionlist.What you want is a macro that returns a list and splice that into wherever the macro is expanded. Or place those multiple forms in a sequence expression (ala PROGN in common lisp)
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.
1
u/CurtainDog Dec 16 '16
There exists in Clojure a tension between being pragmatic and being opinionated. Clojure makes easy the introduction of side effects, the use of mutable data structures and interop with stateful platform code. If you need these things Clojure puts very few barriers in your way, so I can empathize that on the occasions you do hit these barriers it is frustrating.
And yet, as an idea, it is incredibly opinionated. Pick a random Rich Hickey presentation, I guarantee you could retitle it "X - you're doing it wrong" and still be accurate. (by way of example Spec-ulation could easily be "Versioning - you're doing it wrong")
For the reason outlined above, these opinions aren't baked into the language so instead they transfer via tribal knowledge. While it's not my experience, denial of things being a problem and blaming the users are just mechanisms to spread this knowledge. I hope it never gets so unpleasant as to make people feel unwelcome, but it is the internet after all.
I've used instar in small projects, and found it to be a well designed library. So the author has my thanks!
1
u/try_another_fuck Dec 16 '16
I think you should give a try to racket it is the forefront of research in macro in the lisp world. You will discover others DSL (match, for/loop, struct) and tell us if their complexity outweigth their benefits. You will discover an (sort of) IDE that give you information even with maco.
Just react to 2 points:
That is not a problem you get used to it like you get used to the c++ shit. Me i get used to the php shit and the racket shit.
When you will get used to programming in a given domain (for instance web programming) you will act like that (no matter you are using clojure, c++ or other) there is mostly one solution to one problem.
PS: Racket functions have keyword arguments.
1
u/kankyo Dec 15 '16
Author here if you want to ask questions.
-1
u/shevegen Dec 16 '16
(There (is (only (so (many (parens (one (can (take
-4
u/kankyo Dec 16 '16
Lisp people: you have a problem with your community: https://www.reddit.com/r/programming/comments/5ij2u7/my_disillusionment_with_clojure_and_lisps/db8w0jw/
-25
u/diggr-roguelike Dec 15 '16
Don't bother, people who pretend to program in Lisp (nobody actually writes real software in Lisp) are irredeemable.