Python evangelists unite!
Fri Nov 30 07:05:36 CET 2001
I haven't worked much with Ruby, I'll admit, but one of their advertised
"features" sounds like something that violates OO far more than Python's
dynamic members. I don't like singleton functions at all - they let you
cheat by futzing with core implementation details in client code. Yeah,
Python probably allows this, too, but it's not common and certainly not
advertised. A friend argued that it's a waste of code to declare an entirely
new class just to override a method and declare a single instance of it; I'd
say that deriving a new class is clearer, and redefining an instance's
member functions seems kludgy and prone to hard-to-find bugs. (Besides, I
like the Python principle that, while short code is good, clear and succinct
code is more important than the absolute minimum of LOC's.)
Anyway, the point is, while Python allows extra members to be tacked on for
a client's own use, this is not half the violation of OO concepts that a
certain other language regards as a neat feature.
jyrinx at mindspring.com
<brucehapman at hotmail.com> wrote in message
news:baf2f841.0111291428.591f515 at posting.google.com...
> 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...>
> ME: Python's great--you can add members to instances OR classes
> FRIEND: Why would you want to do that?
> ME: Uh...
> 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.
> ME: Yeah, but with dynamicism, I can add a new pane to a GUI
> while it's running. I just change an instance to include a new pane,
> 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...
> FRIEND: And another thing! What's with encapsulation? There's no
> ME: <Screaming and running for cover>
> So, I need some help. I've checked out c.l.p and some on-line
> articles, and I just can't find good practicle examples of a program
> that adds members to instances (or classes) at runtime. Anybody got
> any? I don't want to have to start avoiding my friend....
More information about the Python-list