Python evangelists unite!

Kragen Sitaker kragen at pobox.com
Sat Dec 1 04:28:23 EST 2001


brucehapman at hotmail.com (brucehapman at hotmail.com) writes:
>  FRIEND: Besides, that's awful Object Orientation. If I start adding
> attributes to an instance of a class, it ceases to be an instance of
> that class. If I create a bunch of instances of the same class, they
> should be the same; they should have the same members.

Your friend obviously greatly overestimates their knowledge of
object-orientation (as evidenced by their saying it with Initial
Capitals).  One of the standard OO dogmas is that if FireTruck is a
subclass of Vehicle, then FireTruck instances are (in addition to
being FireTruck instances) Vehicle instances.  Another standard OO
dogma is that subclasses, at least, can define new attributes.  If
your friend accepts these two dogmas, then he must think that
subclassing is "awful Object Orientation", too.

>  FRIEND: That's pretty cool, but it's not a reason, in and of itself,
> to make a language so dynamic. There must be some advantage to being
> able to add attributes during runtime. What are they?
>      ME: Uh...

I don't generally add attributes after __init__, myself.  I like to be
able to summarize what I expect of an object in phrases like "foo is a
valid FireTruck object", rather than "foo is a FireTruck object that
has had the addStuff method called at some point in the past", because
that latter phrase is harder to ensure the truth of.  And I don't like
using hasattr() and getattr() and __dict__ except when I'm extending the
language, doing things that can't be done without them.

>  FRIEND: And another thing! What's with encapsulation? There's no
> private!?!?!?

Some languages have encapsulation, and others don't.  It doesn't have
much to do with whether or not they're object-oriented.




More information about the Python-list mailing list