Python evangelists unite!

Jason Voegele jason at jvoegele.com
Fri Nov 30 13:17:27 EST 2001


"Jyrinx" <jyrinx at mindspring dot com> wrote in message news:<9u77i8$a5j$1 at slb0.atl.mindspring.net>...
> 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.

Neither singleton methods, nor dynamic members are a violation of OO
principles in the least.  They are both, on the other hand, violations
of a static typing principles.  Neither Ruby or Python offer static
typing, so why is this a big deal?  Ruby offers this flexibility
because it's a dynamic language, and it comes in very handy.

For example, I'm writing a Ruby binding to the Object-Oriented
database GOODS.  Some objects are persistent, some are transient.  You
don't know at "compile time" which are which, so it's very nice for my
binding to be able to add persistence support methods at run-time only
to those objects that will be stored in the database.  Without Ruby's
support for adding these methods to individual objects, I'd have to
modify the class, which would mean adding all this persistence-related
stuff to transient objects.  Ruby allows a much cleaner solution: add
the persistence support methods only to those objects that need them.

The point is: don't listen to this kind of argument from someone who
has little or no experience with dynamic languages.  Singleton methods
and dynamic members are not cheating, they're incredibly useful
features that some C++ programmers are averse to because it doesn't
"feel right", because it doesn't follow the "strict interface"
semantics required by a statically typed language.  If you're using a
dynamically typed language, you've already given up the static-typing
safety net, so why bother to live with the restrictions that are
necessary for a static type system?  Remember, in a dynamic language,
class does not equal type.

Jason Voegele



More information about the Python-list mailing list