2 ms·
So there's some boilerplate that needs to happen. With macros, you write the macro to insert the boilerplate, and then you never think about it again. You don't
by zck 11y ago
So there's some boilerplate that needs to happen. With macros, you write the macro to insert the boilerplate, and then you never think about it again. You don't write it, you don't read it, it's not in the way. Without macros, you have to write the boilerplate every time you write the code. You have to read the boilerplate every time you read the code.
Here's the version with macros:
(transaction (do-stuff)
(do-stuff-if-commit-successful)
(do-stuff-if-rollback))
Here's the version without macros:
(transaction (lambda () (do-stuff))
(lambda () (do-stuff-if-commit-successful))
(lambda () (do-stuff-if-rollback)))
Which do you find more readable? Notice how there's no boilerplate in the macro version.
> This appears to be the same as your other example. Java has lambda expressions (since Java 8) that could do this.
What are the odds that Java 8 has provided everything you could want in out of Java? Macros let you add things in a better way than you could otherwise get. Look back to my prior example of Java 5's expanded for. You see how useful that was? If Java had had macros, people wouldn't have had to suffer through nine years without the improved for loop.