5 ms·
This post persuaded me to not take much of a look at Janet. This is also related to why I think that Lisps haven't become the most widely-used programming langu
by kerkeslager 4y ago
This post persuaded me to not take much of a look at Janet. This is also related to why I think that Lisps haven't become the most widely-used programming languages.
Lisp enthusiasts like to point out the power of macros, and macros are the raison d'être for Lisp's homogeneous s-expression syntax. Most other features in Lisp (such as first-class closures and higher-order functions) can exist without s-expressions, but the powerful thing about s-expressions is that they enable Lisp macros.
But with great power comes great responsibility. When I'm writing a program I want as little responsibility as possible while still being able to solve the problem at hand. I don't want to be responsible for memory management and bounds checking, and I don't want to be responsible for the hygiene of my macros at both the definition and the call site.
With C, the responsibility of memory management and bounds checking comes with a power that people actually need to solve problems. For me these problems usually come up in the context of writing my own hobbyist interpreters/compilers, but there are a lot of real world cases where these come up. But often you don't need the capabilities of C, and I'd argue as a result that there are a lot of cases where using C is a bad idea because it's not the best way to solve your problem.
And here's the hot take: the power of Lisp macros isn't actually ever worth the responsibility in my experience. The problem Lisp macros solve is "this code is more verbose/ugly/boilerplate-y/etc. than I want it to be", which just isn't the problem you're writing the program to solve. Whenever you reach for a macro, there's another tool you could be reaching for to solve the actual problem at hand. At the very least, you can just write the code the macro would expand into. There's inherently never a case where the macro is the only way to solve the problem.
If you're good at writing macros, you won't always get burned by them, but nobody is ever perfect at writing macros, so everyone gets burned sometimes. If you're writing software that you actually need to work, the risk is rarely worth it.
When I have written production code in a Lisp (mostly Clojure) I've rarely reached for macros, and often bugfixes have been removing a macro that was of the "so preoccupied with whether or not they could, that they didn't stop to think if they should" variety. And if you spend enough time avoiding and removing macros, you start to wonder why you're destroying your eyesight trying to match parentheses, when the entire reason for the parentheses is to enable something you have to avoid and remove.
And don't get me wrong: macros are cool. "Because I like them" is a totally valid reason to write macros and Lisp.
- foodoos 4y ago> the power of Lisp macros isn't actually ever worth the responsibility in my experience Expand your experience. > At the very least, you can just write the code the macro would expand into. You can "just" get it wrong when the code is used in many places. Consider this as the hot take: macros reduce the number of characters you have to type. I haven't seen anything that beats macros in this metric.
- codr7 4y agoMore importantly, they reduce the number of characters you have to read and maintain. Macros allow writing code that's both compact and readable [0], in lesser languages you have to choose. [0] https://github.com/codr7/cl-redb/blob/ff3a34a31ced7a9668fc952d8040ddb13cad17be/test.lisp#L7 https://github.com/codr7/cl-redb/blob/ff3a34a31ced7a9668fc95... [1] https://gist.github.com/codr7/4bb9442c0c66411643eddd8db0164a2d https://gist.github.com/codr7/4bb9442c0c66411643eddd8db0164a...
- kerkeslager 4y ago> More importantly, they reduce the number of characters you have to read and maintain. So does giving all your variable names one-letter names and putting your entire codebase on one line. Surely we can agree that character count is a poor measure of readability or maintainability. > Macros allow writing code that's both compact and readable [0], in lesser languages you have to choose. Macros aren't the only abstraction that does that, even within Lisp.
- martinflack 4y ago> So does giving all your variable names one-letter names and putting your entire codebase on one line. Surely we can agree that character count is a poor measure of readability or maintainability. Which is why pg advocates symbol count. (Although he seems to love brevity too.)
- codr7 4y agoI urge you to try that theory on the expansion linked in my comment and see where it takes you compared to the macro code. No, but it's the most effective one.