Lists Home |
Date Index |
>Static Typing - Type of variables must be declared at compile time (e.g.
>Dynamic Typing - Type of variables determined from usage at runtime
>Strong Typing - Variables cannot be coerced to unrelated types. (e.g.
>Weak Typing - Variables can be coerced to unrelated types. (e.g. C)
That matches my recent experience of the terms, though I think the
emphasis on variables in that is a bit misleading. Several different
things can have types, notably objects (which exist at runtime)
variables and expressions (which exist at compile time).
Both Python and Java have typed objects - objects have some indication
of their type attached to them - unlike (say) C where objects are just
some bits interpreted according to the expression that refers to them.
Java has typed variables, Python doesn't. Java is a little strange in
that although objects are typed, the interpretation of an object also
depends on the expresion used to refer to it: you may see different
slots ("instance variables" in Java-speak) depending on the compile-time
type of the expression.
C is not weakly-typed in normal use. Most casts are genuine
conversions. If x is an int, (double)x is no different from a
function call that converts an int to a double. The compiler inserts
casts where needed in assignments and prototyped function calls. The
only weak-typing constructs are pointer casts, function calls with the
wrong argument types in old-fashioned C without prototypes, and maybe
one or two others.
As I think Guido pointed out, static typing only catches a fraction of
even the simple non-algorithmic errors you can have. It doesn't help
that you type-checked an integer assignment if the LHS is in inches
and the RHS is in centimetres. It doesn't stop you getting arguments
in the wrong order unless they happen to be of different types.
And the incredible verbosity of common constructs like iteration in
Java is largely due to static typing, and is a source of errors just
by ensuring that your method doesn't fit on the screen.