Programming codex

Coding Standards in C Sharp

Coding Standards in C Sharp

[ad_1]

At one time I implemented FxCop frequently to keep me in line and guarantee my projects satisfy C # coding criteria. Alas, I drifted from FxCop within the last year or two (I believe on account of laziness on my part). During that time, I have followed several coding standards all my own (many of which I’m not too satisfied with).

Recently, a colleague reintroduced me to FxCop (now called Code Analysis) and introduced me to StyleCop – and in between the two of those tools I could not be happier. With those 2 whipping me in line I can say that my code looks similar to the code from the remainder of my team and vice versa. The aim is usually to have coding standards adhered to, but enforcing these standards is difficult to do with a Word file. Every team I’ve been on has a file for C # coding requirements, but if there is no method to assimilate that document with VS.NET or if the team does not take on regular code reviews you are going to have a very tough time enforcing these standards. Having the right tools included in Visual Studio.NET to always remind programmers whether their C # is meeting Microsoft’s rules is massive from not just a “we are a consistent team” standpoint, but for self-gratification as well. Similar to executing unit tests and having all green checkmarks, there is gratification in running FxCop and StyleCop and seeing them both come back with 0 (zero) alerts.

For entertainment, I suggest choosing one of your existing projects and running both tools. Go over each of the alerts (regardless of how minor they appear) and make the essential modifications. When you’re done, review your work and ask yourself if you feel better about what you’ve changed. For me, incorporating XML commenting to every method and property just how StyleCop enforces appeared somewhat unnecessary, but it had a major impact on the readability of my code base for other team members. The hardest part about the adoption of the tools is getting your coworkers to understand the motives for sticking to the process. Ultimately, they will be happier when everyone has used enforceable standards.

Mastering C # is not just about learning Object-Oriented concepts and syntax – it’s also about standards and being a valued team member. A high-level of C # coding expectations will bring you many steps closer to your team when establishing excellent software. In between C # coding guidelines and quality control with unit testing your team will have a tidy, trusted code that they’ll rely upon for the foreseeable future.

FxCop is built-into Visual Studio .NET 2010 nowadays referred to as Code Analysis. Simply be certain to activate code analysis within the project properties window of your projects. StyleCop is found at http://stylecop.codeplex.com/ and it is definitely worth the cost (free).

[ad_2]

Source by Milan Malkani

Share on facebook
Share on google
Share on twitter
Share on linkedin
Share on pinterest
Share on whatsapp

Leave a Reply

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

Search:

Topics

Recent Posts