In September I wrote a short article about writing a clean code. I told you that it is a good habit to implement programs with a one and good style. Today I am going to wrtie something about a special tools which are very useful during programming.
First of all, you need to have a JetBrains ReSharper installed at your local machine. Then you have to download a StyleCop, which is a plugin designed for ReSharper (http://stylecop.codeplex.com/releases/view/79972).
ReSharper allows you to clean your code automatically. When something is wrong with code it highlights it. When you use it for a first time you won’t be able to accustom with it. But after few weeks it will be your best friend during programming. Why should we use it and why is it so popular? It is caused by companies, which are developing large projects. In each project, there are 4-5 developers working on a solution – just think about it – each of programmer has a different style, habits and so on. To avoid a dirty and hard code to maintain, someone came up with the idea of creating a special tool designed for such situations.
Below you can see how does it work in a short example:
Code without any help from ReSharper & StyleCop plugin:
You can see blue & green highlights. Green means that you should think about types of variables, problems with your code (but remember – not with a functionality!), while blue is used to tell you, that you should think about a fix-spacing, comments, etc.
Code after styling:
As you can see, all spacing problems were fixed, it added summaries and InvariantCulture to a conversion from int to string with a .ToString() method.
It was a simple example, but with this tool you can change for example 4 if conditions into one switch in a one second. You are also able to change a foreach expression into a special LINQ, also in one second. It will remember about checking null conditions. On the other hand it is not designed for begineers, because it is not a good way to write your code automatically when you are still learning basics.