C# Coding Standards and Practices

April 7, 2011 § Leave a comment

C# Coding Standards and Practices

Hi Guys, I have seen when working with team How Programming can be a big mess when each one writes the name with their own convention, Its a Horror when it comes to do code review, So I decided that I’m going to cover coding standards and practices, a topic that is often overlooked.

With lot of googling and digging, here is what the Best reputed Organization practices the Naming Convention

Define and Publish your C# Coding Standards and Practices

C# coding standards and practices can quickly become hotly debated among developers when they are discussed. I’ve seen folks go into such a conversation thinking it is a waste of time and getting hotly involved in debate over a particular convention. It is an area where there is rarely a right or wrong, but plenty of opinion. The best advice that I can offer is to make sure you define and document the practices. No matter what they are, identifying what you want to follow is imperative. Once defined, they must be made accessible and communicated to others. This is a great use for a wiki so that others within the organization can contribute.

The following list contains common areas that should be defined within your standards and practices:

  • Source code structure, layout, and formatting
  • Variable naming standards and conventions
  • Rules around commenting your code
  • Exception handling pattern and process
  • Version control and compilation rules
  • Expectations around flow control
  • Programming patterns that should be applied (or avoided)
  • Database related practices

You should document your rules in a clear and concise manner. It is valuable to include a concise coding example that supports the rule, as well as an example that violates a particular rule.

You may also find it useful to break your standards into a series of documents as not all standards and practices apply to all languages. You will likely have some standards and practices specific to the environment if you are an Azure developerASP.net developerC# developerVisual Basic developer, Windows Mobile developer,WCF developer, ASP.net MVCSilverlight developer, orprogramming in C or doing C++ programming. For example, I have standards and practices around use of Session State and View State for ASP.NET applications that would not apply to other types of development.

Enforce Coding Standards and Practices

Coding standards and practices lose their value if not everyone on the team is following them. I’ve been involved with organizations that do formal code reviews that involve going before a review board of sorts. Those meetings can be very time consuming and tedious. I’ve also seen a high number of organizations that ignore them altogether as there may be a single developer assigned to a particular project and they are left to their own devices. I employ a mixture of manual as well as automated code reviews. There are great tools like FxCop, which integrates with Visual Studio, and is included in certain versions of Visual Studio. It has rules that can be customized and tailored to your standards. It quickly analyzes your code and reports on findings. This is a great starting point for analyzing code and looking for hotspots. It is also valuable in Visual Studio Team System to use code check-in rules to force developers to run tools on their own code prior to check-in.

Example Standards

The following links point to a couple of sources where you can find some examples of coding standards and practices that I consider to be worthwhile as a starting point:

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

What’s this?

You are currently reading C# Coding Standards and Practices at Naik Vinay.


%d bloggers like this: