Java and Static Typing
May 18, 2004
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.
About
This page contains a single entry from Stefan Tilkov's Random Stuff posted on May 18, 2004 10:07 AM. The previous post in this blog was D, E, and Extensible Programming Languages. The next post in this blog is OmniGroup Frameworks, Prebuilt. Many more can be found on the main index page or by looking through the archives.
Comments
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.
Posted by: Charles Miller at May 18, 2004 10:17 AM | link
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.
Posted by: Stefan Tilkov at May 18, 2004 10:44 AM | link
But is it a useful tradition?
Do the explicit declarations actually help code comprehension - or are they just noise that gets in the way?
Posted by: Adrian Howard at May 18, 2004 12:15 PM | link
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.
Posted by: Stefan Tilkov at May 18, 2004 4:28 PM | link
