by chowells · 7y ago · 0 comments
I don't think that's an improvement. Languages like Java and C++ don't work that way, and they're the ones being decried for having to spend too much time writing out redundant types.
I think the problem is that people don't treat types as documentation. List them explicitly when it clarifies. When it doesn't, leave them out. A lack of documentation is better than useless documentation. Treat types the exact same way.
Maybe it's because I've spent so much time in dynamically typed languages, but I see var/auto as absolutely essential to making static typing palatable. I'm a big fan of static typing, but I would be much less so if I had to do it without inference/deduction.
List<String> names = new List<String>();
Why not let people write just: List<String> names = new List();
Why did they even need to invent the diamond operator?and yet as soon as you introduce auto you've got the mob bringing out the pitchforks :-)
Your conclusion is the same as mine. Use them when appropriate. When is appropriate? We need some data on that.
ML and Haskell, for example, have basically had (local and hear-global) type inference since the 1980s.
[1] As of, say, 2009 or so where even local type inference was relatively rare in mainstream languages.
(This is obviously a very personal preference and depends on whether it's a code base you're already familiar with, etc. etc.)
I know a lot of teams that conduct code reviews outside of the IDE, so your suggestion wouldn’t help those cases.
Err.. I think it's the other way around.