3 ms·
> , I believe such generic multi-domain libraries would be a hot mess to maintain. I think you (or I) understood it backwards. They see macro as a way to avoid
by Voloskaya 6y ago
> , I believe such generic multi-domain libraries would be a hot mess to maintain.
I think you (or I) understood it backwards. They see macro as a way to avoid multi-domain mess. Each domain could develop its own macro without having to worry about other domains, while in the base language everyone has to be considered.
- Daishiman 6y agoIn practice I have never observed a single domain in which Python's language constructs are terribly insufficient.
- Voloskaya 6y agoI don't think the bar is at "terribly insufficient" to be honest.
- Daishiman 6y agoPython has one of the best ORMs, the best web dev framework, the best REST framework, the best numeric processing library, the best machine learning libraries, and just all around excellent libraries for any domain you could possibly imagine. I have never thought, gee I wish I had macros. I have thought a hundred times more about multi line lambdas, and even so the number of situations where they would make my life easier bs being a source of confusion is very, very small. It's an essentially finished language at this point. The library warts are not worth it given the amount of language machinery you'd have to invent.
- uryga 6y agoi actually think both Django and Tensorflow would benefit from macros. in both cases you spend a lot of time writing what's really a DSL embedded into Python (defining models using a magic metaclass thingy / defining computation graphs, basically writing ASTs by hand). --- for another example, consider Foo = namedtuple('Foo', ['a', 'b']) where the namedtuple function actually has to hack around the fact that it's not a macro: https://github.com/python/cpython/blob/644e94272a89196801825cb69a56377bf62d256a/Lib/collections/__init__.py#L498 https://github.com/python/cpython/blob/644e94272a89196801825... tldr: Foo needs to have __module__ = 'yourmodule' __qualname__ = 'yourmodule.Foo' or else stuff like Pickle won't work right. so namedtuple has to reach into the caller's stackframe to see what module it was called from! this wouldn't be an issue if it was a macro and just expanded to a class definition.
- Daishiman 6y agoSo, I agree that it would look slightly better if it were a macro. Having said that, is it worth the additional language complexity and opening a Pandora's box of footguns? No. The idioms are not _ideal_, but I would not consider that to be dramatically painful, not would I even say it slows down development much. I think it's very difficult to improve idioms at this point without adding complexity in the language to the point where, IMO, it's no longer worth it. I think a strong point of Python vs other languages in the same class is that there's a well-defined limit, both as a community language and language capabilities, as to how much complexity and rope you're willing to give the user.