IsPython really O-O?

Blake Winton bwinton at tor.dhs.org
Wed Nov 14 09:44:42 EST 2001


On Tue, 13 Nov 2001 13:21:09 -0800, Paul Prescod wrote:
>Adam Spitz wrote:
>> In Python, it feels like I'm sneakily hacking an
>> extra method into a class against its will.
>You are doing something sneaky in *any* language because if anyone else
>defines newMethod in any other module anywhere in the system you'll
>overwrite each other. Classes are more or less global variables and so
>are their methods. 

I wonder if this has to be the case.  Perhaps a Class could be made
module-specific, so that any changes to the Class would only occur in
the module they were changed in.  (As an implementation, I'm thinking
of something like the "__spam" changing to "_classname__spam"...  So
if something in module "eggs" adds the method "bacon" to the class
"spam", it would actually go in as "_eggs__bacon", with the
interpreter checking for the module version of the function first, and
if it didn't find it, checking for the base version.  This could also
generalize to nested modules as "_eggs_ham__bacon" for the "eggs.ham"
module, with the interpreter checking for the method in the order
"_eggs_ham__bacon" followed by "_eggs__bacon" followed by "bacon".)

>Python would probably not have first-class syntax to do this until there
>were a way to do it that scaled well to large programs written by people
>who do not necessarily communicate with each other.

Something like throwing a "Method Already Defined" exception if you
step on someone else's toes?  Or more like the module syntax I
described above?  Or something else entirely?

Caveat: I've never found a need to define a method on an object I
didn't own, so all of this is mere speculation.  For that matter, I
really haven't taken much advantage of Python's dynamic nature at all.

Later,
Blake.
-- 
9:40pm up 52 days, 21:07, 2 users, load average: 0.02, 0.09, 0.07



More information about the Python-list mailing list