4 ms·
I don't get the whole "macros make your code incomprehensible" thing that is always brought up. A macro is just another way to add abstraction to your program.
by aidenn0 8y ago
I don't get the whole "macros make your code incomprehensible" thing that is always brought up. A macro is just another way to add abstraction to your program.
You might as well say functions are bad because without reading the source code for the function you don't know what the function does.
A macro that looks like one thing but does something else is a bad macro. We don't throw away functions just because someone can write a function named "sort" that actually randomizes it's argument rather than sorting
- marcosdumay 8y agoMacros are way more powerful than functions. They can hide way more side effects, can fill a namespace, and can surprise you on many other ways. This wouldn't be a problem if those surprises were rare and clearly marked, but the entire reason for macros to exist is to carry the surprises. As a consequence, having macros as the default (ok, second choice, not much better) tool of your language is bad. It's not that macros are bad by themselves, but they shouldn't be used often. Besides, powerful tools do not get well together with dynamically typed languages.
- aidenn0 8y ago> Macros are way more powerful than functions. They can hide way more side effects, can fill a namespace, and can surprise you on many other ways. Abstractions that surprise you are bad. That doesn't mean the tool used was necessarily bad. > This wouldn't be a problem if those surprises were rare and clearly marked, but the entire reason for macros to exist is to carry the surprises. See above RE: surprised. Also, I can usually identify a macro from indentation, as most macros tend to have lambda lists similar to: ((FOO BAR &key BAZ) &body b) which slime will pickup on and indent appropriately. > It's not that macros are bad by themselves, but they shouldn't be used often. If by "use" you mean "write" I agree. I do write macros far less often than I write functions, and this is common advice for lisp programmers anyways. > Besides, powerful tools do not get well together with dynamically typed languages. Not all lisps are dynamically typed, even common lisp has optional type declarations and typed racket takes this further. Also the GP post suggested Ruby, so that's not a great alternative by this argument.