Python evangelists unite!
brueckd at tbye.com
brueckd at tbye.com
Thu Nov 29 23:51:38 CET 2001
> Okay, I was extolling the benefits of Python to a friend of mine. He
> took strong exception to Python's OO model. <here we go again...>
> FRIEND: Besides, that's awful Object Orientation.
I'd ask, "according to whom?" This is a pretty typical knee-jerk reaction
to something new. "Aargh! This is a different way of doing things! MUST BE
BAD!" There are definite cases where both dynamic classes and instances is
useful, but before getting to defensive in answering the "why?" I'd
personally push back a little more with "why not?" (also I'd point out
that just because classes and instances can be so dynamic does not mean
that most or even a lot of them are. It just means that the programmer has
that power available, if needed.)
> If I start adding attributes to an instance of a class, it ceases to
> be an instance of that class.
That's silly. If I put on a hat, do I cease to be an instance of the
Person class? In truth, all less dynamic languages *wish* they had this
feature. Since they don't developers instead have two additional pieces of
work when creating a new class: (1) they have to figure out up front the
total collection of possible attributes/properties instances can have, and
(2) they have to set them to some null-like value if those attrs/props
are not present. So instead of an instance simply not having a property,
all other instances have to have a property with a value that means they
don't have that property. Wow.
> FRIEND: And another thing! What's with encapsulation? There's no
Yawn. ;-) Python provides enough protection against accidental
private-member usage. Unlike, say, Java, Python does not assume you are
an imbecile. IMO your friend probably has not really pondered the true
benefits (if any) of 'private'.
For a huge class of negative reactions to something different, the first
response should often be, "well, have you actually tried it yet?" It's so
common to hear people say that some feature is bad because they can
imagine a case where supposed harm could come from using that feature.
Interesting that you rarely hear people say stuff like "well, I came from
using C++. Now that I've used Python for awhile I can honestly say that
those publicly-accessible members caused all sorts of problems." Instead
you hear, "uh, yeah, I guess it *could* cause a problem. Never has
happened to me though."
More information about the Python-list