Our company is deciding on a policy regarding the use of type inference in our C# and Visual Basic.NET code. During our discussions of what type inference is, one of our developers raised an objection based on an argument made by Andrew Troelson. I've tracked this argument down, and I'm presenting it here because I want to make sure we make an intelligent, rational decision before setting this policy "in stone".
On page 101 of his book, C# 6.0 and the .NET 4.6 Framework, Mr. Troelson says,
In fact, it could be argued that the only time you would make use of the
var
keyword is when defining data returned from a LINQ query. Remember, if you know you need anint
, just declare anint
! Overuse of implicit typing (via thevar
keyword) is considered by most developers to be poor style in production code.
This statement, frankly, surprised me, because it has been my experience that use of var
has been embraced more than shunned by my coworkers across almost all the companies I have worked for since its introduction. However, my sample size is, admittedly, small.
The question, then, is this: Is the use of the var keyword and type inference considered bad form, or is it largely embraced?
Our desire is to establish a policy that is sensible and in line with modern best practices. Your help is appreciated.