Python and Java Compared?

Steven Haryanto steven at haryan.to
Tue Apr 3 09:54:56 EDT 2001


At 4/3/2001 02:11 AM, you wrote:
In addition to this strength of Python:

 > - Dynamically typed and interpreted. Both of these make code clearer,
 > much easier to write and much more malleable. Interpreted code is also
 > easier to test. It is hard to overstate how valuable these factors are
 > for reliability -- far outweighing, in my mind, the value of strong
 > typing (though better optional type checking would be nice to have).

I'd like to add a strength of Java:

- Strong static typing.  Many errors are caught at compile-time,
rather than runtime (which could be a user's runtime and not your
own).  Also, code with explicit type information is often more
self-documenting.



Python, unlike other traditional scripting languages (Tcl, Perl) --
and unlike common misconception -- is also *strongly typed*, i.e.
the interpreter does not automagically type-juggle your variables
in an expression. This works in Perl:

  $a = "5"+6;   # yields 11

whereas this raises TypeError in Python:

  a="5"+6

("5"*6 works though, but it results in "555555").

However, since Python is *dynamically typed*, a variable can
contain various different types of value in the course of a
program.

  a=5    # a is an int
  a="5"  # a is now a string

Static typing can be beneficial in some cases, but I believe
strong typing is more so in more cases.

Steve





More information about the Python-list mailing list