David Hayden [MVP C#]

Sponsors

The Lounge

News

  • CodeBetter.Com Home

Other Links

Teas

Patterns & Practices

Florida .NET Developer

Book Reviews

Tampa ASP.NET MVC Developer Group

Advertisement

Images in this post missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at imagehelp@codebetter.com
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 :)


Posted 05-29-2008 1:38 PM by David Hayden

[Advertisement]

Comments

John Papa wrote re: ReSharper Introspection Severity and the var Keyword
on 05-29-2008 2:21 PM

Amen!

Granville Barnett wrote re: ReSharper Introspection Severity and the var Keyword
on 05-29-2008 3:56 PM

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.

David Hayden wrote re: ReSharper Introspection Severity and the var Keyword
on 05-29-2008 5:08 PM

Agreed. I turned it off as well :)

Troy Gould wrote re: ReSharper Introspection Severity and the var Keyword
on 05-29-2008 7:39 PM

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!

Kyle Baley wrote re: ReSharper Introspection Severity and the var Keyword
on 05-29-2008 10:22 PM

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.

Lex Y. Li wrote re: ReSharper Introspection Severity and the var Keyword
on 05-30-2008 12:24 AM

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.

Mikael Söderström wrote re: ReSharper Introspection Severity and the var Keyword
on 05-30-2008 1:51 AM

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

Oolis wrote re: ReSharper Introspection Severity and the var Keyword
on 05-30-2008 8:41 AM

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.

Oolis wrote re: ReSharper Introspection Severity and the var Keyword
on 05-30-2008 9:25 AM

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.

Kyle Baley wrote re: ReSharper Introspection Severity and the var Keyword
on 05-30-2008 4:26 PM

@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.

Stephen Rylander wrote re: ReSharper Introspection Severity and the var Keyword
on 06-09-2008 4:09 PM

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.