Python from Wise Guy's Viewpoint

Marshall Spight mspight at dnai.com
Fri Oct 24 18:43:59 EDT 2003


"Pascal Costanza" <costanza at web.de> wrote in message news:bnc3cj$pv0$1 at f1node01.rhrz.uni-bonn.de...
>
> class C {
>    void m();
> }
>
> class D {
>    void m();
> }
>
> ...
>
> void doSomething (Object o) {
>    if (o instanceof C) {
>      ((D)o).m();
>    }
> }
>
> "Oops, by accident method m is also defined in D, although I wanted to
> call method m in C."
>
> Doesn't happen in languages with proper name space management. (The
> problem is that Java gives you only the illusion of well-behaved
> namespaces.)

The above code in Java would fail at runtime. What do you think it
ought to do? What would it do in Python? How is this superior to
what Java does? Do you consider this a real-world example?

Does the fact that you didn't respond to the other items
in my post mean you are no longer holding the position that
"explicitly cast[ing] objects" "is one of the sources for potential bugs
that you don't have in a decent dynamically typed language."


Marshall






More information about the Python-list mailing list