Monday, September 8, 2008 #

Turn off Resharper’s suggestion of using implicitly typed locals

If you use resharper with Visual Studio 2008, you may have noticed that it keeps suggesting you use implicitly typed local variable declaration i.e. the var keyword. To me, it is a bit annoying.

 

You can actually find why people think it should exist in the first place:http://resharper.blogspot.com/2008/03/varification-using-implicitly-typed.html

 

There are some valid points, but I am not convinced. I think it is less readable in most of the case. I can’t agree with Ilya that it induces better naming for local variables or better API. You got to name your variables properly no matter what you use, right? It won't make a good programmer better, but it will make a bad programmer even worse.

 

I do agree that compare to

Dictionary<string, Employee> employees = new Dictionary<string, Employee>();

That var employees = new Dictionary<string, Employee>();

does have same readability and it does save you a few key strikes. The benefit is really small, and you have to make judgment on it. The problem is you may have different ideas at different time and different team members may have their own habit. So, in your team, if the coding standard is “Use var whenever you think it good”, it will inevitably cause inconstant coding style. I would rather avoid it by having “Never use var”, you would lost too much after all.

 

So, if you don't like it neither, this is the way to turn it off. From “Resharper” menu, go to “Options…”, and from “Code Inspection”, then from “Inspection Severity”, find "Use Var keyword when possible” and set to “Do not show”

 

 

Posted On Monday, September 8, 2008 6:24 AM | Comments (15)

Copyright © Changhong Fu

Design by Bartosz Brzezinski

Design by Phil Haack Based On A Design By Bartosz Brzezinski