Java and Static Typing
Charles Miller thinks Java’s implementation of static typing is stupid. I’m not sure I agree; while I like languages with dynamic typing/type inference, I’m not at all sure loosening up the restrictions in a statically typed language will lead to a clean design.
Dynamic typing != type inference. Dynamic typing means that the compiler performs no type checking whatsoever: everything is deferred to runtime. Type inference means that the compiler infers the type of all objects from context, and enforces type-safety based on that inference.
Read the “static typing in Perl” slides I linked to from the bottom of the article, they’re a good example of the difference, showing how type inference can be applied to a dynamic language as well.
The beauty of type inference is that there’s no loosening up. Everything still ends up being associated with a type at compile-time, and the compiler still enforces all the restrictions of static typing. The only difference is that the types are implied rather than express.
I could worm my way out of this by saying that I didn’t claim that the two are equivalent, just that I like both; but you are right that I didn’t really think about the distinction when I wrote the statement above.
Maybe ‘loosening up’ is the wrong term. Java, as it is, follows C’s (or rather C++’s) tradition, which mentions and requires types everywhere and very explicitly. To change Java to infer types from variables’ usage would break that tradition and create sort of a half-step towards a more dynamic (although not dynamically typed) language.
But is it a useful tradition?
Do the explicit declarations actually help code comprehension - or are they just noise that gets in the way?
To a large degree, that is probably a matter of taste; to really answer these questions, one would have to compare a version with and without the extra type info.