Python from Wise Guy's Viewpoint

Marshall Spight mspight at dnai.com
Fri Oct 24 16:33:41 EDT 2003


"Pascal Costanza" <costanza at web.de> wrote in message news:bn8550$cpm$1 at newsreader2.netcologne.de...
> Marshall Spight wrote:
>
> > "Pascal Costanza" <costanza at web.de> wrote in message news:bn7a3p$1h6$1 at newsreader2.netcologne.de...
> >
> >>I wouldn't count the use of java.lang.Object as a case of dynamic
> >>typing. You need to explicitly cast objects of this type to some class
> >>in order to make useful method calls. You only do this to satisfy the
> >>static type system. (BTW, this is one of the sources for potential bugs
> >>that you don't have in a decent dynamically typed language.)
> >
> > Huh? The explicit-downcast construct present in Java is the
> > programmer saying to the compiler: "trust me; you can accept
> > this type of parameter." In a dynamically-typed language, *every*
> > call is like this! So if this is a source of errors (which I believe it
> > is) then dynamically-typed languages have this potential source
> > of errors with every function call, vs. statically-typed languages
> > which have them only in those few cases where the programmer
> > explicitly puts them in.
>
> What can happen in Java is the following:
>
> - You might accidentally use the wrong class in a class cast.
> - For the method you try to call, there happens to be a method with the
> same name and signature in that class.
>
> In this situation, the static type system would be happy, but the code
> is buggy.

How is this any different a bug than if the programmer types the
wrong name of the method he wants to call? This doesn't demonstrate
anything that I can figure.

Here's a logically identical argument:

In a typed language, a programmer might type "a-b" when he meant
to type "a+b". The type system would be happy, but the code will
be buggy.

Well, yes, that's true.

My claim is: explicit downcasting is a technique, manually specified
by the programmer, that weakens the guarantees the compiler makes
to be exactly as weak as those guarantees made by a dynamically
typed language.

So I can see a valid complaint about the extra typing needed, but
I see no validity to the claim that this makes a statically typed
language any more bug-prone than a dynamically typed language.
Indeed, it gives the statically-typed languages *exactly the same*
degree of bug-proneness as a dynamically typed language for the
scope of a single function call, after which the languages returns
to being strikingly less prone to that specific class of bug. (In fact,
completely immune.)


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


Marshall






More information about the Python-list mailing list