Typing system vs. Java

brueckd at tbye.com brueckd at tbye.com
Mon Jul 30 21:44:30 CEST 2001


> >  For example, if I need to store a list of points and color
> > values I can't just make an array of (x,y,color) tuples. I need to
> > create a class to hold them and then create instances and store them in
> > an array or Vector.
>
> You seem to be complaining about the lack of tuples, not static type-checking
> per-se.

Hmmm... no, because in Java, for example, to store something in the
container (be it tuple or whatever), the container would have to be
declared as one that can contain my type of object, and to get my object
back out I'd have to explicitly state what it is. For example, if you
want to store the integer 5 in a Java Hashtable, you can't just stick it
in there, instead you do a "new Integer(5)" to create an Object
descendent that can be stored in Hashtable. Then to get it out:

int foo = ((Integer)myHashTable.get(someKey)).intValue(); // bleh

What's the value-add of strong typing here?

> do not have a good code coverage tool.  If the compiler can catch a type error
> for me at compile-time, that is at least one less unit test I have to write.

How so? The type checking imposed by compilers like Java don't seem to
solve any real problems - all they do is free the compiler from blame:

Vector v = new Vector();
String s = "hi";
v.addElement(s);
Integer i = (Integer)v.elementAt(0);

The compiler made me stick in the cast to an Integer, but it didn't solve
any problems for me (the code is still wrong). The only result is that the
compiler can now say, "Hey, it's not my fault - you're the one who cast it
to an Integer!".

Others on here have pointed out that using C++/Java as an example of a
strongly-typed language is a mistake, so maybe my opinion is closer to
"the typing systems in C++ and Java tend to cause me more work and
problems" and not strong, static typing.

> for you.  It would really be nice if Python could add some sort of optional
> type declarations.  It should be technically feasible.

I don't think the technical feasability is the main thing keeping them
out. Can you help me better see how the value outweighs the cost? (I'm not
saying the value is 0, only that for me the cost has always *seemed* to be
greater than the benefit.

-Dave





More information about the Python-list mailing list