4 ms·
https://docs.python.org/3/tutorial/classes.html https://docs.python.org/3/tutorial/classes.html Thanks for the entertaining comment.
by leephillips 1y ago
https://docs.python.org/3/tutorial/classes.html https://docs.python.org/3/tutorial/classes.html
Thanks for the entertaining comment.
- zahlman 1y agoThe fact that the tutorial included in the official documentation (which is quite comprehensive) covers classes (in chapter 9) hardly seems to diminish my point. Python's object-orientation is based on objects. Hence "everything is an object" being taken seriously, reifying many things as objects (intrinsically, without a "reflection" library) that cannot be seen that way in many other languages (notably Java). For example, functions, modules, classes themselves, exception tracebacks, stack frames... And hence the inability to describe instance members directly in the class body: because that's where members of the class (which is an object) are described. Including the methods of the class — which as written are just ordinary functions (which are also objects) that happen to be attributes of the class. The methods (which are also objects) are created on the fly when a function in the class is looked up via the instance. And those objects can be stored for later use. This is what object orientation is supposed to be. Languages like Java are instead class-oriented. You are constantly forced to think about writing classes in order to use objects — you constantly use objects, but you pay for it in class syntax. (Meanwhile, there are non-object primitives.) In Python, you never have to write a class, yet you constantly use objects despite yourself (and "unboxed values" are never accessible from Python).
- leephillips 1y agoI see what you mean. So instead of claiming that Python employs class-based object orientation, I should have said something like: Much existing library code is needlessly rigid and complex, even when supplying simple functionality. This is encouraged by Python’s mechanism of method specialization, which uses single dispatch and class objects. An attempt to re-use methods from a library leads to the expression problem.
- zahlman 1y agoYes, the standard library has a lot of questionable design (some inspired by Java, some by C), and many programmers overuse classes. I'm a fan of (former core dev) Jack Diederich's talk, https://www.youtube.com/watch?v=o9pEzgHorH0 https://www.youtube.com/watch?v=o9pEzgHorH0 .