3 ms·
Considering only production code here. Do use: Common Lisp, Racket, Python, Ruby Would like to use: Julia, Rust, Elixir I metaprogram when I see I have alrea
by pritambaral 8y ago
Considering only production code here.
Do use: Common Lisp, Racket, Python, Ruby
Would like to use: Julia, Rust, Elixir
I metaprogram when I see I have already built a mini-language/pattern in my code. Even when writing Lisp, I begin with simple code without extending the language, and only when I have written a bit do I consider looking for patterns.
- FridgeSeal 8y agoOut of curiosity, why do you have Python on your list? Python doesn’t really support metaprogramming? I’ve written my fair share of Python but don’t remember ever coming across anything meta in the language. Even if it has some passing implementation, it definitely doesn’t have it in the way Lisp/Julia/Rust/etc have it.
- pritambaral 8y ago> it definitely doesn’t have it in the way Lisp/Julia/Rust/etc have it. Yes, but then again, Rust, Julia, and Lisp are _high_ standards of metaprogramming. Python's approach to metaprogramming, like most of its other parts, is simple and concise. For simple tasks that are repeated often, Python sometimes provides easy ways to abstract the how and show only the what. While Python does have metaclasses — which, unfortunately or otherwise, I've never needed to write — I've sometimes found myself reaching for simpler tools like decorators, magic dunder methods, even iterators and generators. And, of course, there's always the ability to generate Python AST, or have something generate it for you. Examples: 1. the new-in-3.7 feature: dataclasses[0]; 2. the library that inspired it: attrs[1]; 3. the (de)serialisation library with a strikingly simple design: marshmallow[2]; 4. the leaky-abstraction of SQL that makes it somewhat composable: sqlalchemy[3]; 5. Google's python bindings for Protocol Buffers[4]; and, of course 6. the lisp-in-Python: Hy[5]; ---- [0]: https://www.python.org/dev/peps/pep-0557/ https://www.python.org/dev/peps/pep-0557/ [1]: http://www.attrs.org/ http://www.attrs.org/ [2]: https://marshmallow.readthedocs.io/en/3.0/_modules/marshmallow/schema.html#Schema https://marshmallow.readthedocs.io/en/3.0/_modules/marshmall... [3]: https://docs.sqlalchemy.org/en/13/orm/extensions/declarative/api.html https://docs.sqlalchemy.org/en/13/orm/extensions/declarative... [4]: https://developers.google.com/protocol-buffers/docs/pythontutorial?csw=1#the-protocol-buffer-api https://developers.google.com/protocol-buffers/docs/pythontu... [5]: http://docs.hylang.org/en/stable/language/internals.html http://docs.hylang.org/en/stable/language/internals.html