r/Clojure • u/honzapokorny • Jan 20 '14
Lisp: more is less
http://jameso.be/2014/01/19/lisp.html6
u/lechatsportif Jan 20 '14
I believe the author has over thought the problem here. Homoiconicity ensures macros dont look strange and clojures preference towards immutability help ensure they won't create bizarre scope or project level madness. As a result, in practice macros in clj tend to make things easier - thread first and with transaction being good examples.
9
u/ItsNotMineISwear Jan 20 '14 edited Jan 20 '14
Also for some reason the author thinks that any large-scale project will be littered with horrible macros. He basically says "because Lisp gives devs the option to write macros, they're going to and it's going to ruin your project." Like any language, it's important to adopt some best-practices and the adage of "don't use a macro when a function will do" is a pretty common one.
4
u/netsettler Jan 20 '14
Yes, I think this is right. There are plenty of standard language features where one can use them irregularly and end up creating a Tower of Babel, too. One can go overboard on use of interfaces, or just use them irregularly, or can use competing patterns, or can differ gratuitously in data structure choices, or use private/protected/public in unpredictable ways, or use managed or unmanaged code irregularly, or other things that just require some agreement among teams to keep things in check and connecting cleanly. Static software will see these things but won't comment on regularity of use. It's like how a spell checker may notice that both "liter" and "litre" are correct spellings but most spell checkers won't tell you that you used one spelling earlier in the document and a different spelling later.
Such problems are even known to the community of programmers in many cases, they're not a surprise, but people probably don't file those problems in the same mental bin ("reasons not to use static languages") and they're instead in other bins ("cool things that I learned in the process of building expertise in this language"), so they're just they're maybe not getting compared side-by-side with things in the bin named "reasons not to use dynamic languages". :)
1
u/Anderkent Jan 20 '14
Like any language, it's important to adopt some best-practices and the adage of "don't use a macro when a function will do" is a pretty common one.
That might be true, but it's happened to me that I wrote a macro because it was the only way to do something that occurred to me at the time, only for someone to come up 3 months later and say 'Why is this a macro? You could do it with <another much simpler approach>'
Presumably in a language without macros I'd find the other way much faster.
(OTOH, we ended up with a hybrid approach in the end - a macro that expanded to a data structure, for ease of defining stuff, and then functions that worked on that data structure. As opposed to the macro expanding to a structure with function definitions inside, or declaring the structures by hand)
5
u/ItsNotMineISwear Jan 20 '14
macros don't extend the language at runtime
1
u/netsettler Jan 20 '14
Usually not. But the capability is there in some dialects more than others. The trend in design has been to do less of this, but in DSLs based on Lisp, especially those interactively used by end-users, and in automatic programming, it can still be an important feature. (This subreddit is Clojure-centric, but the article in discussion was spanning multiple Lisp dialects, so it's hard to narrow the focus and make sense of his criticisms.)
4
u/daGrevis Jan 20 '14
“With great power comes great responsibility.“
0
u/geodebug Jan 20 '14
So you agree with the author?
10
u/netsettler Jan 20 '14
I think the author expresses some legitimate concerns but tries to take on too many things in one article, and I think doesn't support his case in the sense of a slam dunk debate. Lisp is less constrained than other languages, and the work style for using it is different.
I put some more detailed comments in the disqus forum attached to the thread that address his criticisms in more detail, but really it's such a broad area that it's hard to address in one post or thread.
You can also find some comments on the issues of Lisp's size, dynamic nature, and other objections addressed in my Slashdot interview from a decade ago. But the very fact that Lisp has been used successfully for some very large applications suggests this article is not the whole story.
I don't have any objection to him deciding it wasn't the right language for him, and even publishing this as his personal feelings. It's good for people to offer opinions. But when he starts to talk about what's irresponsible to others to do, that's the only part I think is overstepping without a heap more justification. I think it's good to think seriously about what languages and technologies you use, but importantly I don't think you should ever get a free pass on doing that. Long ago, IBM used to be sold on the slogan "No one ever got fired for using IBM." He's not making that argument exactly, but he's sort of drifting close to it, disparaging the technology rather than its use, and implicitly lauding the alternatives on similar grounds.
--Kent Pitman (As it happens, I've worked a lot in Common Lisp, a bit in Scheme, and quite a bit on the design of various of Lisp dialects. That alone doesn't make me right and him wrong. He's still entitled to his position. I'd rather people not think right/wrong here and more understand that there may be multiple legitimate points of view. And my point of view is probably legitimately different than his. The world is big enough to tolerate such disagreement.)
2
u/geodebug Jan 20 '14
Thanks, my response to daGrevis was not to troll but to hopefully inspire a more thoughtful comment (positive, negative or neutral) on the article.
I agree with you that it's not up to the author to decide what is "responsible" for a developer to use. It drags the article into "language war" territory, which has never been interesting.
It's better and more interesting to talk about positives, negatives, and how one might work around the negatives of a technology choice.
I think most of his assertions are really long-standing software engineering questions hidden in Lisp vs Python clothing.
programmers are not language designers
Really the question on whether DSLs are appropriate in a project or not. You can write a DSL in Python or Java as well so it's not about language choice, although Lisp makes it easier.
I'd argue that creating a good public API (or any code that others have to use) is just as challenging.
I think it's a bit of a stretch to label creating a DSL "language design".
Good-bye static-analysis
This is just the classic static vs dynamic language debate.
I’ve never found threading or interprocess communication to be any sort of conceptual bottleneck
I've found multi-threading with shared mutable state so hard that I've moved away from doing it at all, favoring messaging with immutable structures instead.
Simplicity
It's hard to argue against simplicity except for when you need to go beyond the sneezeguards a language imposes. I'd probably argue back that in a language like Clojure, most of the time you're doing things one way and not using all the options available.
There are times where the additional concepts are there for the API and library designers, not for your average glue-coder tasks.
3
u/yogthos Jan 21 '14
Macros can make it more difficult to reason about code, and this is the reason why it's considered to be the best practice to write functions whenever possible. When you look at the code in the wild, most of the libraries follow this rule and don't have many macros in them at all.
I know that I rarely find myself needing to write macros as the language is already plenty expressive. However, there are situations where macros are very useful and allow capturing repetitive patterns and domain specific logic. In my opinion the problem the article raises is completely artificial as it's demonstrable that majority of Clojure code is not macro heavy.
I would also argue that working with mutable data and passing things by reference, as is done in most mainstream languages, makes it much more difficult to maintain large code bases than any amount of macros.
3
Jan 21 '14
I've been in a company that shot it's metaphorical foot with bad macros, and then I went to a company that ruined its code base with some bad python. What does that say about each language? Not much. What does it say about my ability to interview? Nothing good.
0
Jan 20 '14
[deleted]
2
u/yogthos Jan 21 '14
In the end of the day you can write unmaintainable code in any language. The idea that language support for macros in particular makes it somehow more likely that the code is going to be harder to maintain is absurd.
It's much more interesting to read about actual experience from companies using Lisp than arm chair theories on the dangers of macros.
8
u/nonrecursive Jan 20 '14
Learning a language involves more than just learning syntax and semantics. You also need to learn how to write for maintainability. Every language has features which make a large codebase incomprehensible if not managed systematically. Pointers, monkey patching, and convoluted class hierarchies to name a few.
It's unrealistic to think that you can write maintainable code in a new language before spending the time specifically learning how to do so.