Hacker News new | past | comments | ask | show | jobs | submit login

Frankly I doubt you even need metaclasses in the first place (at least in non-library code).

I get that it's a dynamic language but if I need metaclasses for something it's more likely than not to be a hidden technical debt generator.




I think SQLAlchemy makes good use of metaclasses. It's the only thing I've seen that used them in a way that I thought made sense and was well justified (but I have been out of the Python world for a while).

In another language it would be done with code-gen, which would also be fine.

But SQLAlchemy is library code.

I took the time to understand how to use metaclasses, and concluded that I never would, especially not in code I expected another engineer to understand - I expect 90% of people who write Python haven't heard of metaclasses, and 99% have never written one.


There was a time, early on in my python career, that I tried all the different flavors of magic that python provides. These days, I tend to write code for junior developers. I don’t use any magic at all, even when it could make sense.

Once you start playing with magic, you have far fewer eyes and hands that are interested.


In my opinion it's not about dealing with junior developers or even having the ability to understand it. I've been programming for 25 years and to me it's about cognitive load. I despise tricks like this because they put a much higher strain on the programmer. Software is hard enough, let's not make it harder.

If I can look at a piece of code and it's quickly obvious whether it is correct or not is my favorite type of code...




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: