views:

624

answers:

3

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

+1  A: 

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
+3  A: 

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 due 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
+1  A: 

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

If you person that decided you next pay rice 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 lackly enough to decide what tools (and coding standards) are used yourself, then I would just choose ReSharper and read the “clean code” book.

Ian Ringrose