On the object metaphor
The field of computation has many many metaphors. Objects is one of them.
To be honest, I don't really understand object oriented programming. I understand procedural programming aka C.
Procedural programming is like treating your computer as a dumb assistant. You tell it _what to do_ in the exact order(program/script).
Recently I began thinking about OOP in terms of how it can expand the dumb assistant metaphor. So this post is an exercise of trying to articulate it albeit, poorly.
In the real world, objects are dumb things. They sit around and do nothing. It is always a person who finds use for them.
Classically speaking, things have properties and things can be arranged into classes. It is the properties of the *thing* that differentiate it from other things of it's class and things of other classes.
A *class* is an ideal form of an object. Classes don't exist in the real world. Objects do. Classes are merely a way in which human organize things, for the sake of convenience (book stores). This is why sometimes objects fit into different taxonomies.
To organize according to class, is an innate quality in human beings.
For eg) If you have a json file and an xml file, you might instinctively consider naming the variables as json_file or xml_file to indicate the class of the file.
One important thing happens in the real world due the classification into classes. I am sure, you have heard the phrase ... "just another action movie" or "just another chick flick". Once you start classifying things into classes, the objects loose significance of their own.
Every thing is unique, but in the eyes of the class, they are variations of the ideal form.
Now consider activities. Activities have a purpose, require a person and they too can arranged into various classes wrt this purpose. Just like objects, upon classification, each activity can become anonymous as something that someone can do.
Coming back to the programming world, can we use classes as a means to organizing complexity ?
code = dumb assistant
code does some algorithms with some data
One can see from the analogy of the book store that classes come with an inbuilt capacity to store things and classes have a name.
Therefore, in the classical sense, it is quite easy imagine a hash to hold a genre of
books or a table holding the books. A relational database table is a kind of a hash, so one view database design as an act of classification.
Similarly, by purpose, algorithms can be classified into packages(atleast in perl) which are loaded runtime. Most likely the purpose is going to be messing with data of type something.
This makes sense. The dumb assistant is now aware of classes of data and can perform a package of algorithms wrt each class of data. As a programmer, our job is make sure that this dumb assistant does not fuck up and apply the wrong algorithms to the wrong data by giving him _very_ precise instructions.
Thus, using classes in a program is a way of making the dumb assistant multi-task.
Modular programming specifically refers to classifying algorithms into packages for reuse, me thinks. c-style struct design/database design specifically implies thinking about data classification and reuse, me thinks.
Now, let us expand the bookstore metaphor. It makes sense, to have an volunteer for each section. Or, on "world book day" or something, we can imagine a volunteer representing her favorite section.
In fact with a bit of imagination we can imagine a volunteer for every book.
The volunteer can provide a number of additional functions. Because she has the knowledge of the section, she can give more information than what is merely visible.
If we were to tell the dumb assistant to get a book, the dumb assistant can now take the help of these volunteers.
Obviously in the programming world we or someone has to write these volunteers. On our instruction, the dumb assistant can make use of as many volunteers as we want.
Thus code = the dumb assistant taking the help of volunteers in the prescribed order
volunteer = someone whose is aware of a class of data and can perform algorithms wrt each class of data
Is'nt this shell scripting ?
Is'nt this delegation ?
Is'nt this message passing ?
Is'nt this the little people metaphor with more flexibility ?
I know I am not the only one who wants to confuse objects with subject metaphors :)
If you like linguistics, you will be aware of SOV. Maybe that's why we feel cozy when we use the $hey->do_something() syntax ?