4 ms·
Python has operator overloading like C#, which, if used in relatively more interesting ways, can cause code using these APIs to look pretty different from "stan
by ameliaquining 9y ago
Python has operator overloading like C#, which, if used in relatively more interesting ways, can cause code using these APIs to look pretty different from "standard" Python. Python also allows overloading (i.e., defining new semantics for) more interesting things like field lookups and class definitions. This is extremely powerful and lets you do various useful things that are impossible in C#, but it also means you can't take much of anything for granted when using someone else's API, as there might be "spooky action at a distance". And so there's a real cost to learnability and maintainability.
There is something of a culture in Python of not being overly clever, which keeps this stuff in check. (Contrast Ruby, which offers equally powerful language facilities without the cultural norm of not using them for crazy things.) But for relatively all-encompassing frameworks, the ergonomic benefits are often too great to ignore, so you start to see things like Django models and class-based views, which tend to look and feel quite different from "regular" Python classes.
- falsedan 9y ago> There is something of a culture in Python of not being overly clever, which keeps this stuff in check. (Contrast Ruby, which offers equally powerful language facilities without the cultural norm of not using them for crazy things.) Have you seen namedtuple? It's part of the stdlib… and metaclasses are designed for devs to do wildly unpredictable actions when creating instances (not to mention python's OO layer is basically a clever hack).
- icebraining 9y ago"Keeping in check" is not the same as "not allowing". It has metaclasses, but they're rarely used. namedtuples are also a rare case in a large stdlib. How is the OO layer a clever hack?
- falsedan 9y agoMost other OO languages can pass self implicitly, and don't distinguish between initialization & construction. > There is something of a culture in Python of not being overly clever This is the part I disagree with. So much python I read in apps, libraries, web frameworks, and pythonista tweets is needlessly clever.
- icebraining 9y agoMost other OO languages can pass self implicitly That's not an hack, it's a conscious decision[1]. It actually avoids having to implement hacks, in the case of decorators; for example, @classmethod and @staticmethod can be implemented in pure Python thanks to that. It also avoids all the crap that litters JavaScript code, like "var self = this" and bind(), since you can just use different names to those variables. Implicit "this" works in Java and similar because the language is so restricted anyway that an explicit version would be useless. and don't distinguish between initialization & construction. Fair enough, but are they able to do what __new__ does? This is the part I disagree with. So much python I read in apps, libraries, web frameworks, and pythonista tweets is needlessly clever. But compared to which languages? [1] http://neopythonic.blogspot.be/2008/10/why-explicit-self-has-to-stay.html http://neopythonic.blogspot.be/2008/10/why-explicit-self-has...
- falsedan 9y agoFrom that link: > There's no way without knowing what the decorator does whether to endow the method being defined with an implicit 'self' argument or not. How about letting the code object decide if it's a method or a function, using a meta-object protocol to track when a code object is a method? Frankly, Guido's arguments boil down to "I can't see a nice way to not have it", not "here's a good reason to prefer this style". > But compared to which languages? Plain python.
- icebraining 9y agoHow about letting the code object decide if it's a method or a function, using a meta-object protocol to track when a code object is a method? Frankly, Guido's arguments boil down to "I can't see a nice way to not have it", not "here's a good reason to prefer this style". That would add complexity to the implementation and use to solve a specific problem, while leaving others unsolved. In any case, disagreeing with a decision doesn't make it a hack. Plain python. Fine, but I think the claim is that Python's culture avoids being overly clever compared to the culture of languages that offer similar possibilities. Being overly clever in your personal view is inherently subjective and therefore unarguable.