Adding static typing to Python

Justin Sheehy justin at iago.org
Tue Feb 19 14:34:21 EST 2002


"Peter Milliken" <peter.milliken at gtech.com> writes:

> The loose typing of Python is perceived...

Python has strong typing.

It also has dynamic typing, as opposed to static typing.  This seems
to be the thing that you're objecting to.  

Sorry to nitpick, but if you're going to talk about these sorts of
details, getting the terminology right is a good start.

> So I doubt that the proponents of Python in these instances have any
> idea of the true cost of this language "feature" - they appear to be
> wound up in how quickly they can produce a working prototype (or
> whatever) so I suspect their day to day work involves very small,
> manageable projects where the lost efficiency due to loose typing
> isn't really that noticable for them i.e. they "live with it" :-).

I doubt that you have any data to back this up with, and since most of
your talk was about lack of metrics, I don't see that you have any
ground to stand upon from which to criticize others.

I'm currently working on a medium-sized project implemented mostly in
Python that demands serious reliability.  I've also worked on projects
in languages that enforced static typing.  (I've even worked at one of
the sorts of places well-known for using Ada, though I only have a
little bit of personal experience with that language.)  I am familiar
with the issues here.

> I often wonder whether I wouldn't be better off using my real
> language of choice (Ada) because of it's strong typing - it too has
> interfaces to the standard GUI tools etc. My next personal project
> will not be in Python

If Ada is more able to suit the needs of your project (and one major
concern in that area is often a matter of a programmer's personal
taste) then you should use it.

> When I compile a Ada program cleanly I know that 95% of the bugs are out of
> it - before I even start testing! :-) Of course, it takes me longer to write
> up front but overall development effort (in my subjective opinion - since I
> have no metrics :-)) is that it is much lower.

Not only do you have no metrics for your overall development effort, I
am willing to wager that you don't have any to back up that 95% claim either.

> Strong typing requires that you design before you code

This is absolutely false.  

I have personally seen many counterexamples.

Yes, I read your other message explaining what you mean here.  Your
conclusion is still wrong, though.

> You should try it one day :-)

I have used a number of strongly-typed languages, including Python.

I have also spent plenty of time with statically-typed languages.  

> Yes, sane development practices are essential on such large projects -
> doesn't matter what language is used. Part of my argument is that language
> features are designed and provided as further "encouragement" down the path
> of "correct" practices. Typing is recognised as one of these features......

Right, and what practices are correct or useful also depends on the language.

If I was using C++ or Java (or Ada) and the compiler failed to
complain about an obvious type mismatch, I would be quite upset.
However, the Python language encourages different practices, and often
those are such that static typing would be far more of a detriment
than a boon.

To clarify my own position: I would love it if a Python implementation
could do some reasonable type inference, and/or make use of optional
type declarations either for error-checking or optimization.  However,
completely removing dynamic typing from Python would be a disaster.

-Justin

 





More information about the Python-list mailing list