Monday, March 21, 2005

"Everything is an object"

When you've been raised under the aegis of object-oriented programming and design, the only building blocks of the universe you can imagine are data structures that respond to messages. As a result, the word "object" becomes synonymous with "value." I remember being disgusted as an undergrad with Sun's capitulation to the bit-twiddlers in making Java primitives non-objects. Indeed, it was a capitulation, and there are techniques like automatic boxing/unboxing and tagged fixnum representations that allow for fast common cases. But my implicit assumption was that every value should be an object.

I don't personally believe anymore that it's a natural or even useful metaphor to think of 17 as an autonomous agent interacting with other entities by sending and receiving messages. But others much smarter than I am have wrestled with this question, and the jury is still out. But at least now I'm aware of my assumption.

It's useful to keep this assumption in mind when talking to OO people, though. Because they will often assume that the only element of data is the object, they will use the word interchangeably with "value." This leads to confusing claims like this one from a promotional video for Alan Kay's latest endeavor, the Viewpoints Research Institute:
Because everything in Squeak is an object, students can write a simple script to control their experiment.
This has become a running joke in the office, because what on earth does being an object have to do with being scriptable? John Clements made it make sense by translating "object" to "first-class value" -- by making the elements of their workspace values, students were able to manipulate them programmatically. Whether the values are agents, processes, algebraic datatypes, or numbers is irrelevant, but Squeakers think of everything in terms of objects, so that's the terminology they use.

No comments: