Clearing up the Python OO Myth

Python is a good object oriented language, but many people say it is not a "pure" OO language. You could argue this either way: it depends on your definitions. In Python, everything is an object, even functions, methods and integers. That's more "pure" than Java or C++. But in Python, the method abstraction is built on top of the function abstraction. Java calls functions "static methods" and Ruby (for example) says that they are methods on some global object (or something like that...I don't remember the details).

Personally, I think the argument is silly either way. Do you get paid extra to program in a "pure" language? I sure don't. But I'm interested in a historical question: is Python the way it is because it was an imperative language that had OO features bolted on? I think the answer is clearly no.

This common misunderstanding arises from two things: First, people notice that Python builds its method abstraction on top of its function abstraction and not vice versa (as in Smalltalk). This is evident in the syntax. Second, people read the FAQ entry called "Why must 'self' be declared and used explicitly in method definitions and calls?" and in my opinion they misunderstand it.

Python is not an old imperative language that added object oriented features when they became trendy. Python was object oriented in early 1991, when it was first released on USENET (yes, USENET, that's how long Python's been object oriented, from back when USENET was useful). You can still download Python 0.9.1 from there and see that it used roughly the same class syntax:

class AbstractParent():
#
# Upcalls from child to parent
	def addchild(self, child): unimpl()
 	def delchild(self, child): unimpl()

But more important, you can see that Guido was already using the convention of passing "self" as an argument to a method call:

class StripChart() = LabelAppearance(), NoReactivity():
	def setbounds(self, bounds):
		LabelAppearance.setbounds(self, bounds)
		self.resetbounds()

In other words, he'd already figured out (perhaps months or as much of a year before the public release of Python) that having self as a parameter was actually more symmetrical when you wanted to call a chosen method and pass your own "self" parameter. And even in the cases where it isn't more symmetrical, it is at least more explicit about what is going on. This functionality simply isn't available in most other OO languages. On the other hand, Python didn't grow a "super" facility for years...but now it has both.

Furthermore, in December of 1991, after almost a year of public use and more than a year of private use, Guido overhauled the class syntax to be cleaner. This overhaul was backwards incompatible. If Guido had wanted to "fix" his mistake with the "self" parameters, this would have been the obvious time to do it. But he didn't then and as far as I know doesn't now, feel that there is any problem with the fact that self parameters are explicit in the argument list.

In the 2001-2002 time frame Guido overhauled classes again (to add new-style classes) and once again he chose (chose!) not to "fix" this problem. If you don't like the way Python handles self arguments, that's fine. Guido is not God: you are allowed to disagree with him. Sometimes they irritate me. But please do not promulgate the myth that Python is the way it is because Guido hacked object orientation onto a procedural language. OO was one of Python's key features since the day it became public in 1991.

There was likely a phase during Guido's private development where Python had functions but not methods. It is clear that methods are implemented as a special case of functions and not vice versa. But this does not mean that methods were bolted on without much thought. Rather, Guido implemented methods in a manner that was easy and reminiscent of a language he respected and after using it for a while he felt confident that it was as good or better than the way that feature was implemented in other languages. This whole decision process happened before Python was a public language with a user base to speak of. When Python shipped, OO was already a core feature.