I am definitely more than thrilled with the Scala type inference engine, but in a real world environment:
How much of a performance draw back is it?
When is the type inferred, at compile time or runtime?
I am definitely more than thrilled with the Scala type inference engine, but in a real world environment:
How much of a performance draw back is it?
When is the type inferred, at compile time or runtime?
Scala’s elaborate and powerful types exist only(*) during compilation time: they are parsed from source (where you give them), inferred, checked and then, finally, discarded. The last may sound nonsensical, but it is the modus operandi of the JVM (see type erasure) and quite useful from a language designer’s viewpoint.
So, to answer your question: at runtime it makes no difference whether the type was explicitly given or inferred, the only difference is in how long it takes to compile the program.
(*) The 2.10 release will come with a reflection library which allows the program to access its type information also at runtime; this gives added freedom—which if used will of course burn CPU cycles at runtime—but does not change any of the aforementioned points.
How much of a performance draw back is it?
The run time performance is generally said to be comparable with Java. Compilation times are typically longer compared to Java due to the complexity of the compiler.
When is the type inferred, at compile time or runtime?
At compile time.
In this video from about 8:50 to 12:50 Martin touches on usage in "real world" environments and performance. He notes there are many companies using Scala from small startups to large enterprises.
This is mentioned in this answer by Martin Odersky : Why does IntelliJ IDEA compile Scala so slowly? "Type inference is costly, in particular if it involves implicit search."
The question is where the problem with compile times in Scala being longer than in Java come from. Hard for me to say as I'm no compiler construction expert. What I can say is that type inference is obviously not costly in Kotlin and also not in Groovy2.0. What slows down Scala must be something else such as search for implicits.