Hacker News new | ask | show | jobs
by codr7 1155 days ago
More 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/ff3a34a31ced7a9668fc95...

[1] https://gist.github.com/codr7/4bb9442c0c66411643eddd8db0164a...

1 comments

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

> 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.)

I 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.

> No, but it's the most effective one.

That's a perfectly valid opinion which is probably based on your experience, just as my opinion that macros aren't a good tradeoff is based on my experience.

I understand the initial joy of macros, and I'm well aware they're powerful for generating code. But in my experience, they are also not well encapsulated, and as a result, areas of code which use macros tend towards being write-only, where the code becomes hard to read and you're afraid to make changes lest the fragile pile of expansions you've created comes crashing down. In the short run, they seem great, but in the long run, the errors they create don't seem worth it.

I don't know why I've experienced this and you haven't, but I'm sure you have some different experience with macros that leads you to have a different feeling on macros than I do. If you disagree with me, I'd appreciate it if you approached that disagreement without making without assuming I'm an idiot with no experience, and without making arguments like "fewer characters = better" which even you don't believe.

You're right, I do think macros make a good tradeoff. And you're not alone in thinking otherwise, I remember attending a heated panel debate at the International Common Lisp Conference about the pros and cons of macros.

In my case it's based on 20-ish years of using Common Lisp for personal projects.

Admittedly mostly prototyping and figuring things out, but that's my main use case for CL since using it at work is mostly politically impossible.