There are many trade-offs between explicit type declaration, type inferencing, runtime types, and mixtures there-of. The goals of such a design would be to maximize:
- Ease-of-use (not needing to write declarations or think about type)
- Readability, maintainability and diagnosability: self-documentation via declaration
- Efficiency (from having known types rather than using runtime determined type)
The consensus is that the sweet-spot is to use type-inferencing to determine type for entities local to the compilation unit and to require explicit type declaration on entities exported outside the compilation unit. This provides declarative documentation of interface for outward facing APIs, provides static typing for compilation-time detection of type errors and maximum efficiency, and removes the burden of explicit type declaration pn the majority of entities which are local to the compilation unit.
An explicitly declared runtime type (any) could be provided, but it was decided that we should "see how far we can get without it".
Further motivation Edit
Ease-of-use concerns are most in play in the writing of straight-line code, the definition of a class and its member is a more considered affair thus the programmer should consider types in the design of the class and the burden of adding type information is proportionally less significant.
A programmer approaching a new body of code tends to see class definitions in comparative isolation or the in the context of other class definitions. Whereas function bodies (straight-line code, variable definitions, and local functions) are viewed in relation to the enclosing class and the surrounding code. There is thus much more type context for local code. Thus explicit type declaration on class members improve readability more then type declarations on local variables and functions. Because they can be determined, an IDE could show undeclared local types.
Assuming all referenced external types are known, type inferencing within a compilation unit can determine complete type information.
Back to JavaFX Compiler