Python from Wise Guy's Viewpoint

Pascal Costanza costanza at web.de
Fri Oct 24 22:51:30 CEST 2003


Marshall Spight wrote:

>>In a decent dynamically typed language, you have proper name space
>>management, so that a method cannot ever be defined for a class only by
>>accident.
> 
> 
> How can a method be defined "by accident?" I can't figure out what
> you're trying to say.

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

Pascal

P.S, before anyone repeats the same issue again: Yes, Java has a badly 
designed static type system. The example was not a very good one in the 
first place. Doesn't matter wrt to my essential message though.

-- 
Pascal Costanza               University of Bonn
mailto:costanza at web.de        Institute of Computer Science III
http://www.pascalcostanza.de  Römerstr. 164, D-53117 Bonn (Germany)





More information about the Python-list mailing list