Wednesday, April 11, 2007

 

Top 10 Coding Guidelines for C#

Here is a set of coding guidelines that we use to generate code. Using these guidelines we strive to build software that improves the 'able' criteria such as maintainable, readable, reliable, expandable, reusable, etc. The measurement of these criteria is somewhat subjective.

It should be noted that the biggest factors that impact the 'able' criteria are made by selecting C#, .net and Visual Studio development environment. The guidelines merely refine the results.

Here is out top 10 .net C# coding guidelines.
  1. Use Object Oriented (00) principles.

  2. Use unit tests.

  3. Avoid global (or static) properties or variables.

  4. Make extensive use of core .net classes such as Collection and Regular Expressions

  5. Use strong typing and avoid the use of the "object" type.

  6. Use Auto-Generated Code

  7. Use a naming convention.

  8. Use Static Methods and Constants

  9. Use the "this" keyword.

  10. Use Regions to place code in Chapters and Sections.

Labels: ,


Tuesday, April 10, 2007

 

Make Use of #regions When Developing C# .net Code - Coding Guidlines Series

The is part of a .net Coding Guidelines series of blog postings.

Making code readable is an important consideration when developing and maintaining code. The single best way to make code more organized, thus more readable, is to use "region" compiler directive. Regions effectively group your code into sections and chapters.

This is a simple example of code without the region directive. The code is all there but even with just a few lines it can be difficult to read because nothing stands out. This only gets worse when the class is hundreds or thousands lines long.

Here is the same code with regions. It just looks a lot cleaner.

Now when you have found the selection that you want it is simply a matter of double clicking the region tag to see the details.

(example to be added)Even code with regions can get out hand when there are a large number of regions. Then it is time to group the regions into regions.

Labels: , ,


This page is powered by Blogger. Isn't yours?

Subscribe to Posts [Atom]