I think classical-inheritance subclassing is itself harmful. Subclassing creates less flexible software than other approaches, and creates a need for lots of boilerplate.<p>This issue - super in python - drives many new python programmers crazy. However, I suspect most seasoned devs never think about it.<p>These days I never subclass or feel like I want to. Occasionally I'll use 'duck' typing where I would have subclassed in the past but I find that I rarely even need that. The desire to use classes like this sets off an alarm in my head that I'm making my code too complicated.<p>You do a lot of subclassing in Java. Java steers you there because it's so onerous to use dictionaries and arrays/lists/tuples. The syntax for these structures is simpler in python, and so they're more commonly-used.<p>Subclassing is particularly important for creating frameworks in java. You build your world with packages, class hierarchies and 'bean' style objects. Whereas in python you tend to abstract by module - sets of statics, functions and lightweight structures.<p>I believe python would be stronger still had it had removed subclassing altogether, and instead taken the prototype approach. In prototype languages there's no such thing as a class. Everything is cloned off an original master object. Functions and properties are tapped into the clone. Iolanguage has many of these advantages but is far slower, lacks the reach of python's standard library and (I think) also lacks python's awesome list-comprehension syntax.<p>Someone with better articulation than me could generate blog traffic for themselves by creating a pithy post about the difference in style between java and python, and why subclassing is unpythonic. Then we could link to it when these issues come up.
I'm always irritated when I see such post.<p>My kitchen is full of knives, but I accidentally stab my wife only once or twice per year. That's because I'm extra careful.<p>Same thing go with language constructs. I just don't throw features around and see what happens.
Good post with solid examples.<p>At the risk of being down voted into oblivion (I know I would be on proggit by the fundamentalist Pythonistas there): it seems to me that this just adds to the list of Python issues that make the language far more complicated than it really should be.<p>Examples that spring to mind:<p>- The ongoing saga with the GIL (although I realize this has advantages in simplifying C extension development) [1]<p>- String formatting changing seemingly from 2.4 and every version thereafter [2]<p>- The 2.x/3.x split (yes I know there are reasons)<p>- Version issues for scripting [3]<p>- Syntax inconsistency. I know this one will be controversial but I'm referring to things like the fact that del() is a operation<p>- Other issues [4]<p>Isn't something like Ruby or Lua a lot cleaner in this regard? I ask this question seriously.<p>[1]: <a href="http://www.dabeaz.com/python/GIL.pdf" rel="nofollow">http://www.dabeaz.com/python/GIL.pdf</a><p>[2]: <a href="http://kuoi.com/~kamikaze/read.php?id=287" rel="nofollow">http://kuoi.com/~kamikaze/read.php?id=287</a><p>[3]: <a href="http://news.ycombinator.net/item?id=1712035" rel="nofollow">http://news.ycombinator.net/item?id=1712035</a><p>[4]: <a href="http://www.quora.com/What-are-the-main-weaknesses-of-Python-as-a-programming-language" rel="nofollow">http://www.quora.com/What-are-the-main-weaknesses-of-Python-...</a>