And 'var accounts = calculateAccounts(something)' is literally less readable, because now you dont see what exactly accounts is.
Var statement speed up writing, then are either irrelevant or gets rewritten to types for better readability.
Map<String, MyExtremelySpecificAndVeryLongTypeName> myExtremelySpecificAndVeryLongTypeNameMap = myExtremelySpecificAndVeryLongTypeNameMapProvider.provide();
literally anything to reduce the number of line breaks needed for a single statement is welcome.Yes, code review is arguably worse, but most people who write Java do so with an IDE and the type is never unknown at that point.
Also, if your function is big enough to where the type of var is not very clear, it likely shouldn’t be passing code review regardless.
This reminds me of a developer writing in jRuby because "it was better". While he was in the company he'd still give support to his own works, after leaving nobody else wanted to pickup those "better" things and would prefer to write workarounds to the tool, it effectively became a black box that few could improve and even worse to test. As result, those portions had to be rewritten in proper Java so that we'd be able to deeply measure/test and improve.
Never again.
I’m in agreement that when the information isn’t in the rvalue that you shouldn’t use var.
That isn't necessarily a huge win: it does force a compile change that isn't obvious from the source. And a refactoring tool could have performed the code change automatically so it's not as big a deal as it might have been.
I do still really like it in the `var list = new ArrayList<String>()` case though.
Maintenance involves a lot of reading of unknown code. That is literally the situation where you are rewiting var to specific types to figure out what is going on.
Ideally this could all be dealt with via tools. An IDE that shows whatever the user prefers, but is actually saving into a format defined for the repo.
If it should be createAccounts, nothing is lost unless you have multiple account types in which case you would call it createUserAccounts, create adminAccounts etc.
Please point me to an objective measure of "readability" that holds for all people. And then demonstrate that your example is "literally" lower on that scale.
Drives me nuts because you really can only write code for those programs with an IDE that is prepared for the case. Try to edit the code directly from the github web interface and it won't compile.
> Drives me nuts because you really can only write code for those programs with an IDE that is prepared for the case.
Usually people have strict rules for that (e.g. pep8), and most text editors will do it for you with little configuration.
Where did I write this? It’s almost as if there’s nuance in programming.
Var helps when you’re duplicating information that is already known. Your example is clearly not that.