Hacker News new | ask | show | jobs
by kstrauser 1370 days ago
I’ve been writing Python professionally for over 20 years, and I’ve needed to use the things here once. It was highly encapsulated inside one module of an ORM-type project, where other code wanted to use it without having to know anything about its implementation details.

You can do these things in the extremely rare cases that you must, but other than that you shouldn’t.

1 comments

I’m surprised to hear your opinion on this. I have around 12 years of python experience and I find metaprogramming to be, by far, the most important part of Python. Without the extensive ability to rewrite underlying functionality in a way that was approachable to both novice and adept users, I don’t think we’d have seen a widespread adoption of the language to begin with.
I was referring particularly to metaclasses. Decorators, etc.? All the time.
I guess I don’t often touch metaclass either, although after reading this article it gave me some ideas on how I might better implement object validation patterns. That being said, I also have recently become acquainted with pydantic, which does take care of some of that.
Pydantic’s a great example of a good use of metaclasses. I’ve seen them abused in places where there were far simpler ways to accomplish the same goal, and promptly ripped that code out.