Re:Macros in Python
by michaelhoffman on Monday May 13, 2013 @01:44PM
(#5700130)
The implementation of namedtuple is pretty crazy, but the interface is simple and doesn't change the language semantics.
I'd argue that "fields as a string with spaces inside, or maybe a list of strings" is changing language semantics quite a bit.
We're used to namedtuples doing it like this now, but if namedtuples didn't exist, "fields as a list of strings with spaces inside, or maybe a list of strings" would definitely not make it past code review and probably get me yelled at by my future colleagues.
We think that with some discipline, it is possible to come up with macro transformations which are both useful and understandable by a programmer. This means setting clearly defined semantics for the transformations, which is difficult but doable.
If you think macros are kinda crazy (well, they are!) you should look at the implementation of such pythonic constructs like `namedtuple`, the `ast` module and the new Enum library coming out!