Typing system vs. Java

Christopher Barber cbarber at curl.com
Tue Jul 31 13:09:27 EDT 2001


<brueckd at tbye.com> writes:

> On 30 Jul 2001, Christopher Barber wrote:
> > This is a bad example because the code is doing runtime, not compile-time
> > checking.  I was talking about the advantages of compile-time checking.
> 
> ?? Please review the example - that's compile-time checking there.

No it isn't!  The (Integer) cast is not performed until run-time.
 
> > Here is how this would be written in Curl:
> >
> >    let v:{Array-of String} = {new {Array-of String}}
> >    let s:String = "hi"
> >    {v.append s}
> >    let i:int = v[0]        || ERROR: can't assign a String to an int
> 
> But what benefit have I gained? 

You have detected a bug at compile-time instead of run-time and you didn't
have to write a unit-test to find it.

> The only reason it's an error to begin
> with is because the language is forcing me to name the type. 

The language does not force you to specify types, this would also be legal,
but you would not see the problem until you actually executed the code:

   let v = {Array}
   let s = "hi"
   {v.append s}
   let i = v[0]    || runtime error
   
It is your choice.  If type declarations were added to Python in a similar
fashion, then it would not have to impose any burden on developers who don't
want to use them.

> The fact that the compiler can detect my breakage of the 
> language-specific rules doesn't really advance the notion that 
> strict compile-time checking is beneficial.

Sure it does.  You might not believe that it is worth the trouble, but it
clearly has some benefits.

Another definite benefit is that knowledge of compile-time types can allow the
compiler to generate much better code.  We know this is true from our
experience on the Curl language.  Obviously it would be a lot of work for
Python to actually deliver this benefit, but it

> What is a real world problem that would not have existed if Python had 
> strict compile-time checking, and how common is such a problem? 

Here is a real-world problem: a developer wants to use a language with
compile-time type checking and rejects Python because it doesn't have it.

> The few times I've had this sort of conversation I've kind of felt that
> people's reasoning was like "I use language X. Language X without strict
> compile-time checking would make big programs a mess. Therefore, big
> Python programs would be a mess."

Well, I actually used Python on a number of projects a couple of years ago and
did spend more time than I would have liked writing tests to detect type
consistency.  I found myself writing comments next to variables indicating
their intended type.  I would much have preferred turning those comments into
actual type declarations.

I don't think that lack of static type declarations makes Python at all messy.
It is still an interesting and useful language.  I just think that it would be
better with the ability to use static typing when you want to.
 
- Christopher



More information about the Python-list mailing list