21

Just found StyleCop, looks like something worth using for my projects. Then I found out you could use it with ReSharper (a tool I've also never used). So I downloaded ReSharper, as well as StyleCop for ReSharper. I'm just a bit confused about it, though:

  1. With just StyleCop installed (no ReSharper), I get yelled at for referring directly to private variables in code-behind. It wants me to instead do this.variable. Alright, fine.

  2. If I use just ReSharper, it tells me to remove all of the 'this' calls I just added. Which one is better?

  3. If I use ReSharper + StyleCop for ReSharper, it now tells me to add 'this' to all private member references (just like StyleCop did all by itself). However, now it also wants me to add 'this' to all of the controls I'm referencing from the .aspx page (i.e., Label.Text = this.variable -> this.Label.Text = this.variable).

I'm so confused. What is the best standard to follow? Or am I just fine doing it the way I am now (Label.Text = variable)?

Habaabiai
  • 725
  • 2
  • 8
  • 11
  • 5
    +1 for trying out ReSharper. You'd think the forums were filled with their sales people given all the praise, but it really does live up to the hype (mostly). It has its own tag here, so don't forget to read some of the "best-of" to get up to speed: http://stackoverflow.com/questions/tagged/resharper – Michael La Voie Oct 06 '09 at 19:10

3 Answers3

14

The key point is consistency. Your particular formatting with regard to this point comes down to personal preference.

Does the extra wordiness provide additional clarity as to which variable you're referencing or does it obscure the meaning by flooding the page with extra text?

This is a judgment call. They do enforce other rules that make sense; however, a large part of what they do is enforce consistency. As @Martin said, feel free to disable rules that don't make sense for your workflow.

Michael La Voie
  • 27,772
  • 14
  • 72
  • 92
  • If you're interested in 'personal preference', then don't use a tool like Resharper of StyleCop. If you're interested in standardized code and obviating the need for most code reviews, then pick one of the packages, use the out-of-the-box rules and leave your personal preferences for things like art and movies. – Quark Soup Jul 14 '18 at 18:49
11

Sorry when working on a team it all comes down to understanding the politics; after all, we work to get paid!

If the person that decided your next pay raise uses StyleCop, then you should always include the “this.” likewise if the boss uses ReSharper you should do what ReSharper says.

There are a lot more important wars to win this, e.g. 10,000 line classes, over sized method

If you are luckly enough to decide what tools (and coding standards) are used yourself, then I would just choose ReSharper and read the “clean code” book.

Michael La Voie
  • 27,772
  • 14
  • 72
  • 92
Ian Ringrose
  • 51,220
  • 55
  • 213
  • 317
2

I think it's up to you which conventions you want to follow (it's a matter of personal preferences). At least in ReSharper, you can edit the rules to no longer show certain warnings/hints.

M4N
  • 94,805
  • 45
  • 217
  • 260