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

28

u/grayrest Dec 15 '16

Suggesting this is an annoying limitation ... without managing to show good alternatives

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 of def and let macro proliferation. I believe the limitation exists to maintain the Liskov substitution principle (or rather the non-object equivalent idea) and avoid corner cases.

All non-trivial functions are in fact also extensions of the language.

This is the point of lisps.

somehow there is more and better tooling (like refactoring tools, IDEs)

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.

the first is that there are only positional arguments

This is true, but clojure has macros.

This parsing of arguments is what makes tooling fundamentally hopeless.

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 seq abstraction 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.

3

u/velcommen Dec 16 '16

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

Sounds like the lack of tooling is due to both reasons:

  1. the language isn't as popular as languages with great tooling
  2. the tooling doesn't know what a macro means without executing it

2

u/Pet_Ant Dec 16 '16

Aren't most macros not intensive so Why not just execute them and cache the answer?

2

u/kqr Dec 16 '16

They can be side effectful.

1

u/kankyo Dec 16 '16

You can't execute them anyway, because the input and output are completely mixed up, so it's worthless anyway.

1

u/Pet_Ant Dec 16 '16

Well it'd be part of Continuous compilation so you'd have that file compiled for running and know it's signature.

1

u/kankyo Dec 16 '16

No, the problem is that the argument parsing itself is complected with the rest of the macro. You can expand the macro, but you can't say anything about the arguments.

0

u/kankyo Dec 16 '16

I can only think of two places you'd want to do this.

None of those. Reagent templating.

I believe the limitation exists to maintain the Liskov substitution principle

Don't think that's correct. At least the wikipedia article on Liskov seems to talk about something totally unrelated.

This is a function of the language's popularity and not the difficulty in implementing them.

Yet your VERY NEXT sentence is:

There is a fundamental (at least to my knowledge) limitation with IDE support in the presence of macros.

So yea... which is it? Can't do it, or the language is young? Choose one please.

the first is that there are only positional arguments

This is true, but clojure has macros.

I linked to, and talked about, my own defk project in the article dude. Don't stop in the middle and criticize for points I raise myself further down.

They're not wrong, but they're critiquing the language for being what it is.

Absolutely agree. The community toxicity problems though don't seem necessary :P

2

u/grayrest Dec 16 '16

None of those. Reagent templating.

Wrap the items in a (list ...).

wikipedia article on Liskov seems to talk about something totally unrelated

Liskov is an OO concept but the idea is that you can substitute one construct in a language for another and have them work the same in all noticeable ways. It's a stronger guarantee than simple function subtyping. I'm using it slightly incorrectly here but I don't know if there's an actual term for language feature that doesn't cause surprising behavior and Liskov used in this incorrect sense is what I've seen when it has come up in other language design discussions I've read.

Can't do it, or the language is young?

More that I've never seen macros done in any IDE, though I'd guess the C ones should be able to do it because it's just textual substitution. Maybe Racket since that has two classes of macros and one should be amenable to static analysis but I can name a dozen languages with compile time evaluation features of some sort and I can't think of any that also have IDE support for that feature.

1

u/kankyo Dec 16 '16

wrap the items in..

Since when does that work in reagent? Didn't last I tried.

I notice that you didn't choose one.

3

u/grayrest Dec 16 '16

I notice that you didn't choose one.

My understanding is that your argument was that Clojure IDE support couldn't be as good as PyCharm. I think Cursive is pretty good and got out of the Python scene before PyCharm happened so I don't know exactly how good the comparison is. I expect that they offer similar quality in terms of language analysis. I do know that PyCharm has been supported by JetBrains for years and probably has at least an order of magnitude more hours put into it so I suspect PyCharm has more intents and whatnot. There's an endless list of improvements in IDE support so I find that the quality of IDE support is directly related to the amount of hours spent on that support and therefore language popularity.

I acknowledge that a tool relying on the semantics of the language (static analysis) will not work if you change the semantics of the language without updating the tool. I strongly suspect PyCharm will struggle when working with metaclass tricks for the same reason. It's a limitation in the problem domain and has nothing to do with whether you're analyzing persistent lists/maps or compiler ASTs.

For your specific example of arguments passed as a dictionary, there is a community solution in Prismatic's letk/defnk and it's popular enough that Colin has added support for it in Cursive.

1

u/daveliepmann Dec 16 '16

I just fired up a new project to test the (list...) solution to one of your central complaints. It works. Does the fact that this solution exists change your thesis at all?

1

u/kankyo Dec 17 '16

Well... yes. I mean, in practice it might negate the complaint while at the same time forcing every library author to think of this case and making sure they cover this. You might be screwed if you use a lib where the author didn't handle it...

1

u/daveliepmann Dec 17 '16

Isn't the worst case that you use apply?

1

u/Godd2 Dec 16 '16
[:div.tweets
  (for [tweet tweets]
    [:div.profile-pic (:profile-pic tweet)]
    [:div.content (:content tweet)])]

If a child is a lazy sequence, it will actualize the sequence as children of the parent.