4 ms·
I appreciate your reply, but Django never “removed tracebacks” and I would love to see a declarative form that didn’t use metaclasses in some way. Here’s the ~
by orf 6y ago
I appreciate your reply, but Django never “removed tracebacks” and I would love to see a declarative form that didn’t use metaclasses in some way.
Here’s the ~20 lines of cowboy code you’re referring to[1] - collecting the declared fields and setting an attribute containing them.
Not exactly the kind of thing that should make you mad, and rather than overkill it’s exactly the use case for metaclasses.
And to top it off, that metaclass is completely optional, if you want to create a list of fields and pass it into BaseForm then go for it. Most don’t.
1. https://github.com/django/django/blob/5776a1660e54a95159164414829738b665c89916/django/forms/forms.py#L24 https://github.com/django/django/blob/5776a1660e54a951591644...
- carapace 6y ago> I appreciate your reply Cheers! > Django never “removed tracebacks” I don't want to get into a juvenile back and forth, but I must insist that Django did so suppress tracebacks. I don't know what it does today but I remember clearly patching the server code to re-enable them and that the '--traceback' CLI switch didn't do it. > I would love to see a declarative form that didn’t use metaclasses in some way. Here you go: https://pypi.org/project/html/ https://pypi.org/project/html/ Clever design, elegant code, under 20k (including docs and tests), no metaclasses. > Not exactly the kind of thing that should make you mad, and rather than overkill it’s exactly the use case for metaclasses. There is no use case for metaclasses. GvR called that paper "The Killing Joke" for a reason. ( https://www.python.org/doc/essays/metaclasses/ https://www.python.org/doc/essays/metaclasses/ https://www.youtube.com/watch?v=FBWr1KtnRcI https://www.youtube.com/watch?v=FBWr1KtnRcI ) I read it for kicks, because I'm that kind of freak, but it's not the kind of thing that you should ever use in production code. What made me mad is that Django's gratuitous use of metaclasses broke my junior dev. The kid was doing the right thing and it was exploding in his face with an inscrutable error message: that's on Django.
- orf 6y ago> Here you go: https://pypi.org/project/html/ https://pypi.org/project/html/ That’s not even the same thing - it’s a (horribly old) library for generating HTML. We’re talking about forms: sets of typed fields including validations that can be optionally rendered to HTML. Think wtforms[1] > There is no use case for metaclasses. There are, that essay (about Python 1.5 no less) does little to dissuade people from using them, going so far as to offer concrete code samples. It’s also hopelessly outdated: nobody uses metaclasses like that at all, especially not for tracing! It’s hard to blame it though, this document was written before even decorators where introduced. And let’s not ignore the call to authority by pointing out that GvR uses metaclasses extensively while working on type hints, GaE libraries, and even in his early asyncio code. In actual fact metaclasses a few use cases, including the most common: syntactic sugar. Like anything this can be heavily abused and is most useful when creating libraries rather than used within traditional application code. In any case, shunning it wholesale is stupid. Half remembered issues with junior developers are not great arguments against a useful part of a language. Who’s to say that it was even related to metaclasses, and your apparent allergy to them isn’t colouring your memory? 1. https://wtforms.readthedocs.io/en/2.3.x/crash_course/#getting-started https://wtforms.readthedocs.io/en/2.3.x/crash_course/#gettin...
- carapace 6y agoI really don't want to argue about this. You're not going to convince me that Django isn't an overblown toy. I'm not going to convince you that it is. Same with metaclasses, you're not going to convince me that they're a good idea (despite what GvR does with them) and I'm not going to convince you that using them is irresponsible. So what are we left with? > That’s not even the same thing But html.py (would have) solved the problem we had. without the nasty surprise. > In any case, shunning it wholesale is stupid. No, it's conservative. That's a different thing. I want to be able to hire someone who can modify a form. The more complex and obscure the the code is (even if it's only twenty lines long) the smaller the pool of folks who can use it with mastery. Think about it. Anyway, I'm off learning Erlang/OTP now and it really makes Python's runtime look like a joke in comparison. Web-app backends are Erlang-shaped, not Python-shaped. Not using it sooner makes me feel stupid.