G
Gareth Erskine-Jones
var can make things more readable when the RHS is explicit about the type it
returns. But when the RHS is not explicit it makes things less readable, it
introduces uncertainty.
I don't disagree. I do think there is a greater degree of subjectivity
here than you think though - as you say, when the RHS explicitly shows
the type then I don't see the problem - but at least one poster has
objected to:
var i = 2;
where the type of the RHS is perfectly clear (although in this case I
wouldn't use var because I don't see any particular benefit).
My personal practice, in those cases where use of var is optional, is
to explicitly specify the type. I then tend to look back through the
code and replace explicit types with var where I think it improves
clarity without introducing any potential problems.