CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

David Hayden [MVP C#]

         .NET Tutorials, Patterns, and Practices

ReSharper Introspection Severity and the var Keyword

I flagged a blog post the other day from a news feed where someone implied that they had removed ReSharper 4.0 Beta because they did not agree with the ReSharper 4.0 hints regarding the use of the var keyword. If you install the ReSharper 4.0 beta and don't change any of the Introspection Settings in the options, ReSharper will offer you the hint of using the var keyword when declaring variables, etc. It may seem like a suggestion, warning, or even an error when you see the little squiggle, but hey, it's a hint.

Now the beauty about these little hints, suggestions, etc. is that they teach you a little about what is possible in your programming language. Maybe you didn't realize the var keyword existed and when you could and could not take advantage of it. Better yet, and here is the real kicker, you have the option of adjusting the settings:

 

 ReSharper 4.0

 

Therefore based on your coding standards and beliefs, you have the ability to personally adjust the settings for the various hints, suggestions, warnings, errors, etc. So before you jump into the mistake of un-installing ReSharper ( or any tool ) on such a coding style disagreement, you may want to see if you can adjust the settings to your particular style :)



Comments

John Papa said:

Amen!

# May 29, 2008 2:21 PM

Granville Barnett said:

That suggestion is so annoying, think the first thing I did was turn that suggestion off when I installed one of the first EAPs a while back.

# May 29, 2008 3:56 PM

David Hayden said:

Agreed. I turned it off as well :)

# May 29, 2008 5:08 PM

Troy Gould said:

To uninstall ReSharper and lose so much just because of one annoyance is a bit extreme.  

If I was that dogmatic about all software, I would ever touch a keyboard!

# May 29, 2008 7:39 PM

Kyle Baley said:

I went the opposite direction. I have ReSharper converting everything it can to var automatically during a (Ctrl-Shift-Alt-F) code format. I love it.

Incidentally, when you see the hint "squiggly" for this (or any) rule, you can press Alt-Enter, select Inspection Options, and alter the "severity" of the rule right then and there.

# May 29, 2008 10:22 PM

Lex Y. Li said:

Didn't anyone notice that you can turn off this "var" rule by setting solution "Language Level" property to "C# 2.0"? The default value is C# 3.0 which automatically turns on the var rule.

# May 30, 2008 12:24 AM

Mikael Söderström said:

Kyle: So you prefer var instead of the "real" type? Why is that?

# May 30, 2008 1:51 AM

Oolis said:

At least that one is easy to turn off, I still haven't found out how to stop every delegete from being wrapped inside its own nested type region.

# May 30, 2008 8:41 AM

Oolis said:

Lex Y. Li: I am sure everyone does realise that, but it has the disadvantage of marking all other c# 3 features as errors, and no real advantage over simply adjusting the specific setting.

Oh and I currently have my settings adjusted to use the var, but only where the default setting does it, on the same line as newing a constructor, so the type is there anyway.

I think its growing on me, looks silly now to have the type written twice on the same line, redundant somehow. (Well after working a bit in python lately, even the var itself is starting to look a little redundant.)

One of the (few) worst things about c# is the amount of boiler-plate so anything that reduces that is ok with me.

Now if only resharper could convert everything into lambda expressions, I could truly out-guru my colleges.

# May 30, 2008 9:25 AM

Kyle Baley said:

@mikael

I commented when JP posted on it over here: codebetter.com/.../got-var.aspx

The short version is: Most of the time, I can either glean the type easily (when combined with a new statement or by appropriate naming) or I don't care what specific type it is (e.g. IList vs. IEnumerable vs. my own implementation).

I know a lot of people don't like it but it works for me. That said, I won't defend my position to the death. If I'm on a team that prefers not to use it, I'll bow to the majority without much fuss.

# May 30, 2008 4:26 PM

Stephen Rylander said:

I'd prefer it simply kept var off.  Since I can't even pass an inferred type around to other methods it doesn't provide much help.

# June 9, 2008 4:09 PM
Check out Devlicio.us!

Our Sponsors

Free Tech Publications

This Blog

Syndication

News

CodeBetter.Com Home