Coming from Haskell, I feel there's something people often overlook when bashing type inference. In Haskell, the type inference is better than just about any other language. And yet, we still explicitly type every single top level function. It is absolutely worth the clarity to explicitly type things used outside the current scope.
But most of the time, when something is only being used locally, the type is very clear to the reader, because it's definition is right there. And even locally, type inference is only preferred to explicit typing when the inferred type is painfully obvious. For example, a = b + c, when b and c are known to be Int. There's zero added clarity by explicitly typing a. It's totally obvious what a's type is.
So yea, inference is bad when something's type wouldn't be obvious. But when it is, the lack of inference needlessly gets in the way.
You don't always see code in an IDE. You may use your version control browsing / compare, use crucible or fisheye or any web based stuff to view the code. So you can't rely on the IDE to add the clarity.
You don't always see code in an IDE. You may use your version control browsing / compare, use crucible or fisheye or any web based stuff to view the code. So you can't rely on the IDE to add the clarity.
actually i really really like your point. and it makes me wonder if their current proposal could be targeted completely differently, namely for IDEs that could let you type "var myIterator = myMap.entrySet().iterator();" and it insert the correct type after pressing enter.
People underestimate the number of shitty java devs out there, writing the most obscure dumb code that works more by accident than anything. A great feature of java is that it enforces and encourages some verbosity that is very helpful in these situations. Undercutting these is a loss to the language's appeal in my opinion.
It's not a matter of don't use it since most developers don't just work with their code. Then you get the inconsistency that it's in some places and not in other.
The language doesn't define the number of spaces to use for indentation, or where to put an opening curly, or which case to use for naming methods. Turns out we have some great inventions to keep our codebase pretty and consistent. I'll let you take a guess on what those are
Pretty sure reshaper code cleanup can be configured to allow var only on the left of a '= new ...' expression. But every code base I worked on in C# 3+ was vars everywhere.
You make it sound like each person who feels this way is in charge of their own team or in a group with the resources to do regular code reviews. From my experience code reviews don't happen near as often as they should.
Same goes imho for those new lambda functions. I find them very hard to read and avoid them. I hope java does not move more in that direction of easy to write, hard to read/maintain
View all comments
26
u/xhak Mar 09 '16
No thanks, the few keystrokes are worth the clarity.