Explicit Frustration of the Self

Nicodemus nicodemus at globalite.com.br
Sat Jan 4 13:46:14 EST 2003


DeadWisdom wrote:

>Another thought: how OO is Python?  It allows me to create Objects, I
>guess.  But do these objects really have methods?  I don't think so. 
>Not with the way self acts now.  Right now, you are effectively,
>creating functions and then calling them with the first argument
>outside of the parenthesis, and to the left of the function, and a
>dot.
>  
>

I find this vision extremely simplistic and limited. Object orientation 
is basically a way to unite the data and the operations that manipulate 
this data. This raw definition can be obtained in any language, even one 
that is *not OO*. The CPython API, for instance, is mostly OO. Don't you 
believe me? Look at this usage of the basic C API:

{
    PyObject* dict = PyDict_New();
    PyDict_SetItemString(dict, "x", PyString_FromString("12") );
    PyObject* value = PyDict_GetItemString(dict, "x");
    if ( value != NULL ) {
        //...
    }
    Py_DECREF(dict);
}   

Note how this would look like translated to a C++ interface (which is 
clearly Object Oriented by your claims):

{
    PyDict* dict = new PyDict();
    dict.SetItemString("x", new PyString("12") );
    PyObject* value = dict.GetItemString("x");
    if ( value != NULL ) {
        //...
    }
    delete dict;
}


If you find that there's a huge difference between the two, I think 
you're wrong. The difference is mostly sintatic in this case. But notice 
that python looks more like the C++ version than the C version:


    d = {}
    d["x"] = "12"
    value = d.get("x")
    if value is not None:
        #...
    del d

>I really don't see much of a difference between foo(o, "Hello ") and
>o.foo("Hello ").  It must be easy from the point of view of the python
>programming, all you bassically do is mangle it to "Object_foo(self,
>blah)", and pre-process all "object.foo(" to "object_foo(".  Seems to
>be.
>

Because there's really little difference. And it is implemented that 
way, at the lowest level (no preprocessing involved). How do you think 
it is implemented in C++? You're basically complaining about how the 
language seems to be implemented, instead of the actual usage. You 
sholdn't really care, since you don't write object_foo(self, blah), but 
self.foo(blah) instead, which is what you want.

>So the only real difference is that Object.foo won't conflict with
>OtherObject.foo.  But that doesn't seem like the basis of OO.
>

And what are the basis of OO? Call methods as self.foo() instead of 
foo(self)? Well, python DOES that, even thought that *is not* the basis 
of OO.

>In the end OOP is all about the revolution, not of efficiency or
>computational effectiveness, but of how we can understand the
>structure of the world that we create, its objects, its functions. 
>

Which python allows perfectly.

>The idea of the explicit self retards this understanding, I believe,
>and forces us to view python objects as code, not objects of a
>pseudo-reality.
>  
>

Well, that's your opinion.









More information about the Python-list mailing list