2014-01-26

On object-oriented programming.


This sounds vaguely familiar.

I first encountered the concept of object-oriented programming in the late 1990s when I somehow acquired a copy of Practical C++ Programming by Steve Oualline. It was way beyond my computing knowledge level, I had written the tiny beginnings of a choose your own adventure style game in QBasic and was learning the basics of HTML, but I was enough of an enthusiast to slog through a good chunk of the book, even after realizing it wasn't anything I was actually going to use any time soon. The first thing I got out of reading about object-orientation, aside from new uses for words like class and parent, was the sense that programming was more complicated than I had thought. The second was that the architecture of programming was almost as much about making the workings of computers comprehensible to humans as it was about making computers do what we want them to.

Whence object-oriented programming?

The name object-oriented programming was coined by Alan Kay in the 1960s to describe the type of architecture he was working on while developing the Smalltalk language. The structure of Smalltalk was influenced by LISP, Sketchpad, and particularly Simula, which is considered an object-oriented language even though it predates the classification. Kay's central concept for object-oriented programming was that programs should be divided into distinct entities, like the cells of an organism or the separate computers in a network. These entities would protect their internal processes and data and would work together strictly by sending and receiving messages. In a 2003 email, Kay defined true object-orientation as "only messaging, local retention and protection and hiding of state-process, and extreme late-binding of all things." and added that he didn't think any languages besides Smalltalk and LISP existed that could meet this specification. It's interesting that Kay doesn't explicitly include either classes or inheritance, the concepts that most struck me on my first brush with C++, as important factors.

Object-orientation in Python.

Python is quite object-oriented in that everything in Python is an object or a label for an object (a variable). However, Python doesn't fit Kay's concept of object-oriented programing in at least one important respect: Python objects are almost entirely lacking in privacy. This means that, despite conventions such as special variable names to discourage taking indiscriminate advantage of this, all of a Python object's data and methods are generally directly accessible to the rest of the program. If the object architecture in Python is a code of etiquette then in a language like Smalltalk its a code of law. Smalltalk objects sit in separate cells passing notes under the doors while Python's inhabit a single room but, like polite guests at a fancy tea, they refrain from eavesdropping on neighboring tables... for the most part.

Image created from CC images by Ciro Cattuto and Scott Davies

3 comments:

  1. That metaphor was actually pretty beautiful. (And, after I finished reading, I finally understood what that image was supposed to represent!)

    It was interesting reading Kay's thoughts about object oriented programming, and then seeing how python contrasts with that.

    ReplyDelete
    Replies
    1. Glad you enjoyed it. I ended up reading a lot more about the history than I needed for this post. It's pretty fascinating.

      Delete