Category Archives: General

StyleCop + Resharper = StyleCop for Resharper addin

If you’re a .Net developper then you MUST use ReSharper. I you don’t, I suggest you to have a look at this very nice video demonstrating some of the feature of this Visual Studio addin. If you also like having a clean C# code, then you might also use Microsoft StyleCop tool.

I just found this a very cool Resharper plugin that allows Microsoft StyleCop to be run as you type, generating real-time syntax highlighting of violations:

The StyleCop for Resharper plugin is hosted on CodePlex and is free. I think it’s a must have for any .Net developer. Its author really did a good work 🙂

kick it on

Microsoft StyleCop vs Agility

When I write code, I try to keep it as clean as possible by following rules that I define and use in all my project. Those rules can be the ordering of elements within a class, or the way I choose name for my properties and methods…

Microsoft created a tool that analyzes C# source code in order to enforce a set of style and consistency rules : it’s StyleCop (available for free to download). StyleCop defines a lot of rules, for example:

  • Element must begin with an upper case letter
  • Field name must begin with a lower case letter
  • Prefix local calls with the “this” prefix

It is possible to enable or disable each rules separately, and this is what most users will do. Running StyleCop on one of your project can lead to thousands of warning. You can then choose which rules you want to keep enabled.

I started to use StyleCop the project I’m working on at job about one week ago. After disabling some of the rules I didn’t wanted to fix yet, I found a rules that was giving me a lot of warnings:

  • ALL elements must be documented

Hmm… This means that each single method or properties in my project must have a documentation… Well, if documentation is good lets start writing documentation everywhere. I though I will take a couple of classes per day, and write the entire documentation. I started with opening one of my class, and found this method:

public void OpenDocument(IDocument document)
// ...


StyleCop wasn’t happy because there wasn’t any documentation, so I wrote one:

/// Open a document
/// IDocument to open
public void OpenDocument(IDocument document)
// ...

Then, I don’t know why but I asked myself “what the hell this documentation is going to help the user of the class ???”. Because one month earlier I went to the AgileTour (a french event about Agile methods), I remembered the Agile Manifesto:

  • Individuals and interactions over processes and tools
  • Working software over comprehensive documentation
  • Customer collaboration over contract negotiation
  • Responding to change over following a plan

I was thinking a couple of minutes, and then I decided to remove the StyleCop rules about documenting EVERYTHING in my code. I think that would be a waste of time and that would preventing me to put good comments where it’s really needed such explaning an algorithm or why I choose this way over this other way to do the job.

I’m still using StyleCop to have a set of rules about the style of my code. But for now, that’s it ! I think it is very important to make the differenciation between documentation and comments. If documentation is needed because it will generate a document outside the application then it might be usefull. But if the documentation is written just to have it, I prefer forget about it.

.NET 4.0 universe

A couple of days ago, I found this nice post giving a poster that show the new stuff in the next major version of the .Net framework:

The poster is available in PDF and in Deep Zoom format (pretty cool !).

So, to be consice, .Net 4.0 is:

  • a one more step to get Silverlight and WPF closer (Visual State Manager support in WPF)
  • new WPF controls (ribbon, datagrid, calendar, datepicker…)
  • new input extension to handle touch screen device
  • parallel extension (ParallelEnumerable in System.Linq)
  • new XAML functionality
  • new stuff in Workflow, Data and Web systems (I don’t know them enough to give details).