|
|
|
|
|
by jnhnum1
4791 days ago
|
|
Other author here:
Like lihaoyi said, it's true that the way we defined things doesn't match standard Python namespacing, but it saves some typing and I think it's easy to get used to the semantics of our case classes. Our macro just transforms the "namespace tree" that you would normally get from writing code like that into an "inheritance tree", where all the subclasses' names are at the level of the top class. If you wanted to do something like this with proper namespaces, you can probably do something similar without macros using metaclasses. |
|
Your macropy is very interesting, but please do not use this argument. "Saving some typing" is the least interesting side-effect of some macros.
To clarify my point: in most of the industry, we all fight hard to garden big codebases with intricate dependency problems. I am convinced that code complexity management is very far from a solved problem, and I hope advanced tools like macros can help there.
But "saving a few keystrokes" is very often at the heart of the stupides issues we have with code complexity.
Two examples:
+ "from x import " <-- this saves a few typing, but it become extremely annoying as soon as your code get more than 10 modules.
+ template.render(tpl_file, locals()) <-- this feeds the template space with shit and makes it much harder to trace data between templates and models. I daily revile the guy who typed the "*locals()" in the Mako doc.