Sponsored By Aspose - File Format APIs for .NET

Aspose are the market leader of .NET APIs for file business formats – natively work with DOCX, XLSX, PPT, PDF, MSG, MPP, images formats and many more!

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 :)

This entry was posted in Uncategorized. Bookmark the permalink. Follow any comments here with the RSS feed for this post.

11 Responses to ReSharper Introspection Severity and the var Keyword

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

  2. Kyle Baley says:

    @mikael

    I commented when JP posted on it over here: http://codebetter.com/blogs/jean-paul_boodhoo/archive/2008/04/22/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.

  3. Oolis says:

    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.

  4. Oolis says:

    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.

  5. Kyle: So you prefer var instead of the “real” type? Why is that?

  6. Lex Y. Li says:

    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.

  7. Kyle Baley says:

    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.

  8. Troy Gould says:

    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!

  9. David Hayden says:

    Agreed. I turned it off as well :)

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

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>