Typing system vs. Java

Chris Barker chrishbarker at home.net
Fri Jul 27 23:14:11 CEST 2001

John Goerzen wrote:

> To me, the benefit of Java or Python over Perl comes into play with
> large apps.

I think Python is far superior to Perl for large projects, but because
is has nice support for clean syntax and modular programming, not
because of strong typing. The previous poster has a good discussion the
question of whether strong typing is as advantageous as you may think.

> From what I hear about Python, it is weakly-typed like Perl.

Python is dynamically typed, and NOT like Perl!

> are many times where I would like strong, static typing and some times
> when I'd like to override that.

As the previous poster mentioned, you can do type checking in your code
if you want to:

import types
def function(i,j):
    if type(i) <> types.IntType or type(j) <> types.IntType:
	raise TypeError("both input values must be integers")
    #do something with i and j

Clearly this is something of a pain, so if you really think you are
going it a lot, you are using the wrong language for your problem and or
programming style.

> 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 compile time type checking is an important criteria: Python is not
your language! Even the above example is a runtime check.

> If so, how would I go about asserting type
> compatibility at "compile time"?  (Or as close as Python gets to that)

Essentially, it can't be done.

My major thought is this: Compile time type checking is vastly over
rated: I suspect you won't miss it much, and the dynamicism of Python
will buy you much more that you lose: try it, you'll probably like it.

One more thought: it is important when trying  a new language to learn
to program in a style appropriate to that language -- write Python that
looks like C (or JAVA), and you won't like the language.

As an example, my graduate advisor started using MATLAB, he like it at
first, but started out by re-writing a bunch of FORTRAN routines in
MATLAB. Soon he found that they ran really slow, and he never really go
the hang of writing MATLAB like MATLAB. After a couple of years, he went
back to using FORTRAN, and using MATLAB for interactive plotting only.
I, on the other hand, put some effort into learning MATLAB techniques,
and even re-wrote a number of his translated-from-FORTRAN routines in
more MATLAB native syntax, and they ran much faster. I used MATLAB for
years, and like it a lot. (Now I use Python + NumPy for most of what I
used to do in MATLAB, of course)

-good luck, Chris

Christopher Barker,
ChrisHBarker at home.net                 ---           ---           ---
http://members.home.net/barkerlohmann ---@@       -----@@       -----@@
                                   ------@@@     ------@@@     ------@@@
Oil Spill Modeling                ------   @    ------   @   ------   @
Water Resources Engineering       -------      ---------     --------    
Coastal and Fluvial Hydrodynamics --------------------------------------

More information about the Python-list mailing list