Python from Wise Guy's Viewpoint

Pascal Costanza costanza at web.de
Fri Oct 24 23:00:16 EDT 2003


Marshall Spight wrote:
> "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?

You should be able to choose unique names in the first place. The 
problem Java has here is that there is no safe way to avoid that in 
general. There is a risk of name clashes here.

There is some information about one way to properly deal with namespaces 
at 
http://www.cs.northwestern.edu/academics/courses/325/readings/packages.html

There are also other approaches. For example, there exist several module 
systems for Scheme. (I don't know a lot about them, though.)

I don't know how Python handles potential name conflicts.

> 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."

No.

Pascal





More information about the Python-list mailing list