dynamic typing questions

Carl Banks imbosol at aerojockey.invalid
Sat Dec 20 04:18:27 CET 2003

Jason Tesser wrote:
> OK what are your guys thoughts here?  How have you all
> overcome the lack of static typing?  Is Python a 
> bad decision here?   By the way we will be using
> Postgres in the back if that matters to anyone. 

Maybe try the confrontational approach, if all else fails:

Acknowledge that static typing is "cute."  Then mercillessly press him
on how often it really helps, and how much time does it save relative
to Python.

Whenever he cites an advantage of static typing, ask him how often it
really helps.  How often does the compiler really catch that, and is
this really something that Python won't catch at runtime?  

If he cites the ability of the compiler to catch incorrectly passed
arguments, point out that Python can still catch these at run time,
probably as well as Java could.  Remind him that static typing can
catch these only if the incorrect argument happens to have a different
type: static typing is a swiss cheese protection mechanism.

If he cites the ability to catch spelling errors: first point out that
that's unrelated to static typing.  Some statically-typed languages
have this problem (Fortran).  And a dynamically-typed language can
require declarations.  But, even though Python doesn't, it's not that
serious a problem in Python.  Unlike a certain other dynamically typed
(I guess) language beginning with P, variables just don't pop out of
nowhere if you just use them.  So the only time Python can't catch a
spelling error is when it's on the left side of an assignment (or
imported, or whatever).  If he says that's still worse than Java,
concede it.  It's true after all.  Then ask him how often that
happens, and how much time he thinks that will save compered to

If he says that compiler errors are easier to locate than runtime
errors, point out that Python, like Java, has a very good exception
handling mechanism that identifies the locus of errors.  While you're
at it, ask him whether debugging run time errors was ever that bad.
After all, Java has those, too.

At the same time, pimp the advantages of dynamic typing.

Ask him if he's ever written a class, a union, or done some other
silly thing to define a variable that can have a "special" value.
Remind him that this isn't necessay in Python, thanks to dynamic
typing.  (Incidentally, this happens to me a lot.)

Ask him how many times he's defined some ridiculous class hierarchy to
get some pathetic, contrived imitation of polymorphism.  Point out
that, in Python, this isn't necessary.  Things don't have to be
subclasses to be polymorphic.  Subclasses can be used for what they
were intended for: inheritance.

Ask him how often he uses type casting (which should be a lot, since
he prefers Java).  Remind him that every time he uses type casts he
defeats the point of static typing, and has to go though more effort
to do so.

Ask him if he's ever gotten a Runtime error in Java for a type casting
error.  If no, or not often, ask him why he expects this so much in
Python.  If yes, ask him if he felt annoyed that the Java compiler
wasn't able catch it for him, or happy that Java's runtime was up to
the task.

I believe there is very little practical advantage of static typing.
Most of the advantages are small, cute little things, but not things
that won't still be caught at runtime by Python.  The wrong type is
almost certain to be caught by Python sooner or later.

And, in the end, I really don't think type mismatch errors are very
common (compared to other types of error).

Finally, if you still end up using Java, count your blessings.  Java
is not that bad.  You could be using C++ or Visual Basic.

CARL BANKS                      http://www.aerojockey.com/software
"If you believe in yourself, drink your school, stay on drugs, and
don't do milk, you can get work." 
          -- Parody of Mr. T from a Robert Smigel Cartoon

More information about the Python-list mailing list