4 ms·
...am I the only one who finds type inference bad, at least when "reading the code as documentation"?
by nnq 14y ago
...am I the only one who finds type inference bad, at least when "reading the code as documentation"?
- thebluesky 14y agoTypes for method and constructor parameters are always explicitly specified. Type inference generally used for local variables and method return types. This strikes a good balance between having no type info (e.g. python) and having type info for everything (java). The convention in Scala is to specify the return type of a method if the return type is complex. In practice the type which is inferred is pretty obvious: val x = 800 vs. val x: Int = 800
- webreac 14y agoIt gives the freedom to put the type when it is useful for reading and to remove it when it is annoying for reading. It is very different from others because this language assumes the developer is smart.
- lmm 14y agoI think a class's public API should always specify its types (including method return types). But for local variables inside a method, the type information is often just noise.