Typing system vs. Java

John Goerzen jgoerzen at complete.org
Fri Jul 27 09:54:50 EDT 2001


Hi,

I am currently familiar with Perl, C, and Java and am looking at
Python.  I have some questions about its "strong-typedness" (or lack
thereof).

To me, the benefit of Java or Python over Perl comes into play with
large apps.  For my purposes (no flames please!), Perl works great for
small scripts and stuff, but its almost total lack of typing,
prototyping, etc. causes major trouble with larger projects.

One nice thing about Java is that the programmer can control exactly
how tight the type-checking is and whether it occurs at runtime or at
compile time (dynamic vs. static).  I can, for instance, write methods
that care naught about what is passed in (they can take an Object),
which essentially renders the type checking there little tighter than
Perl.  I can write methods that return Objects, and the caller will
then have to cast them back to the appropriate type -- and a runtime
error will result if they're casted to the wront type.

Or, I could write methods that accept objects of a type anywhere up
and down the object hierarchy, being as specific or as general as
desired.  The compiler will do as much checking as possible at compile
time.  Usually I want it to do lots of checking, but sometimes it is
nice to be able to override.

>From what I hear about Python, it is weakly-typed like Perl.  There
are many times where I would like strong, static typing and some times
when I'd like to override that.  Java has a lot of problems (its
bloated and inconsistent API is the largest) and I'd much rather use
some other language for large projects.  However, it's valuable to me
that as many things as possible be caught before runtime.  Do you
think that Python would be a worthwhile language to investigate given
these criteria?  If so, how would I go about asserting type
compatibility at "compile time"?  (Or as close as Python gets to that)

I want to be able to write methods that take only certain types of
objects (or their descendants).  It is also useful to be able to cast
back from a general object to a more specific one (dynamic type
checking).  Or it could be just basic things as enforcing passing an
int rather than a float or a string.

Thoughts?

Thanks!

-- 
John Goerzen <jgoerzen at complete.org>    GPG: 0x8A1D9A1F    www.complete.org



More information about the Python-list mailing list