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”

 

 

Print | posted on Monday, September 8, 2008 6:24 AM

Feedback

# re: Turn off Resharper’s suggestion of using implicitly typed locals

Left by Hans at 1/6/2009 3:55 AM
Gravatar Just wanted to let you know: You're not alone!
Apart from the fact that var is handy e.g. with LINQ operations, I don't like this lazy declaration style very much. Or maybe I just have to get a little warmer with it...

Anyway, at this time I have disabled the mentioned ReSharper options, too, to prevent it from pointing this out over and over again.

# re: Turn off Resharper’s suggestion of using implicitly typed locals

Left by Xavier at 3/10/2009 2:33 AM
Gravatar Thank you for your post. I just installed Resharper and I was wondering why it kept suggesting using "var"!

I use "var" for LINQ queries (because it was done for that) and nothing else!

I saw a wonderfull example of "var" and "extension methods" in the help of QuickGraph (CodePlex):

var edges = new Edge<int>[] { new Edge<int>(1,2), new Edge<int>(0,1), ... };
var graph = edges.ToAdjacencyGraph(edges);

Try to understand how to use it for your own needs!
It took me half a day!

# re: Turn off Resharper’s suggestion of using implicitly typed locals

Left by M at 3/31/2009 4:07 AM
Gravatar thanks, Var just makes the code less readable... been googleing this problem for a while..

# re: Turn off Resharper’s suggestion of using implicitly typed locals

Left by Nir at 1/7/2010 3:29 AM
Gravatar Thanks, it's very annoying. Your explanation was very clear.

# re: Turn off Resharper’s suggestion of using implicitly typed locals

Left by Adam at 4/9/2010 4:40 PM
Gravatar I agree completely. When code is close together,
var x = new Something();
return x.field;

you can tell what it is... but when there is a lot of code separating it, it makes it hard to tell.

Using var reminds me of the way dBASE / FoxPro pretty much started out (without any type), so you would have
x = 1
y = "some string"

and later on, checking
if (x=y)
would cause errors.

# re: Turn off Resharper’s suggestion of using implicitly typed locals

Left by Chris Marisic at 8/5/2010 8:41 AM
Gravatar The var keyword should be used for all complex types IMO, for primitive types it's a subjective view.

var is impossible to make the code less readable. It's not possible to do var bob. lalalalalalala bob = new bob(). Having Bob bob = new Bob() is farrrrrr less readable. This is not the dynamic keyword. It's merely removing verbosity from the code that adds noise.

# re: Turn off Resharper’s suggestion of using implicitly typed locals

Left by Bob Miner at 8/24/2010 7:01 PM
Gravatar Thanks for this post. I use var for LINQ but believe otherwise a more specific type is appropriate and clearer when possible. var reduces clarity in my opinion, hiding type information.

# re: Turn off Resharper’s suggestion of using implicitly typed locals

Left by Keener at 12/21/2010 5:28 PM
Gravatar I say let me decide if I want var or not, I don't need a suggestion on it. This should be turned off by default. Bless you for finding out what setting this was. It will always be turned off on my machine.

# re: Turn off Resharper’s suggestion of using implicitly typed locals

Left by Casper at 4/1/2011 6:36 AM
Gravatar Thank you for letting me get of this retarded warning!

# re: Turn off Resharper’s suggestion of using implicitly typed locals

Left by Strict Typer at 6/23/2011 1:31 PM
Gravatar Fantastic tip! Thank you!

# re: Turn off Resharper’s suggestion of using implicitly typed locals

Left by Dave at 8/30/2011 12:50 PM
Gravatar Thank you! This was driving me nuts in the trial and making think about not buying it!

# re: Turn off Resharper’s suggestion of using implicitly typed locals

Left by David at 5/23/2012 11:08 AM
Gravatar Thank you. This "recommendation" from resharper is ridiculous.

# re: Turn off Resharper’s suggestion of using implicitly typed locals

Left by outlook Customer support at 8/18/2017 6:19 PM
Gravatar There is support team available but for special email support team is here to resolve your any query related to, mails then visit: Outlook Support

# re: Turn off Resharper’s suggestion of using implicitly typed locals

Left by son oh gong at 3/6/2018 12:21 AM
Gravatar I say let me decide if I want var or not, I don't need a suggestion on it. This should be turned off by default. Bless you for finding out what setting this was. It will always be turned off on my machine.

Run 3 like its previous games have you running in space. It’s not just making you run out of boredom but making you run to have fun. Run and jump in the different levels of obstacles in the game.

# re: Turn off Resharper’s suggestion of using implicitly typed locals

Left by sava at 5/28/2018 11:10 PM
Gravatar 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
y8
stick war hacked

Your comment:





 

Copyright © Changhong Fu

Design by Bartosz Brzezinski

Design by Phil Haack Based On A Design By Bartosz Brzezinski