Search Wiki:
Resource Page Description
This document covers many aspects of programming with C#, from naming, structural and formatting conventions to best practices for using existing and developing new code.

Background

It's the manual developed at Encodo Systems AG for developing with C# and .NET, but many of the concepts and ideas can be applied to any programming language. The intent of this document is not to codify current practice at Encodo as it stands at the time of writing; instead, this handbook has the following aims:
  • To maximize readability and maintainability by prescribing a unified style.
  • To maximize efficiency with logical, easy-to-understand and justifiable rules that balance code safety with ease-of-use.
  • To maximize the usefulness of code-completion tools and accommodate IDE- or framework-generated code.
  • To prevent errors and bugs (especially hard-to-find ones) by minimizing complexity and applying proven design principles.
  • To improve performance and reliability with a list of best practices.
Wherever possible, however, the guidelines include a specific justification for each design choice. Unjustified guidelines must be either justified or removed.

Whereas the Encodo Handbook draws mostly on in-house programming experience, it also includes ideas from Microsoft’s Internal Coding Guidelines and Design Guidelines for Developing Class Libraries and benefits as well from both the IDesign and Philips coding styles as corroborative sources.

Using the Handbook

This handbook mixes recommendations for programming with C#, .NET and the Encodo libraries (code samples draw from these libraries, but access to them is not required). It includes rules for document layout (like whitespace and element placement) as well as design guidelines for elements and best practices for their use. It also assumes that you are using Microsoft Visual Studio 2005 or newer.

This document is a work-in-progress and covers only those issues that Encodo has encountered and codifies only that which Encodo has put into practice and with which Encodo has experience. Therefore, some elements of style and design as well as some implicit best practices are probably not yet documented. Speak up if you think there is something missing.
Last edited Oct 7 2008 at 8:24 AM  by mvonballmo, version 2
Comments
Taco wrote  Oct 8 2008 at 8:38 PM  
Thank you for sharing these code guidelines!
A few remarks:
Chapter 6.5.1 (Virtual) The method DoUpdate should be marked protected instead of public according to your guidelines.
Chapter 6.9.1 (Bit-sets) The enum should be called QuerySections (plural) instead of QuerySection.

With kind regards,
Taco.

cupcakeboy wrote  Oct 13 2008 at 10:50 PM  
That's a very thorough, very well-written document. Thank you so much for sharing it.

mvonballmo wrote  Oct 17 2008 at 7:37 AM  
@Taco: Thanks very much for the input; it's nice to hear that you read it so thoroughly! I've added your changes for the next version.

@cupcakeboy: Thanks for the kind words and thanks for reading!

mvonballmo wrote  Oct 27 2008 at 8:36 AM  
Version 1.5.1 incorporates all the feeback we've received since releasing version 1.5. This version includes a relaxation of property naming rules suggested by Joshka (in the discussions) and small logical fixes found by Taco.

pmoriarity wrote  Oct 29 2008 at 9:45 PM  
7.15 Using Event Handlers
protected virtual void RaiseLocked(EventArgs args)
{
EventHandler handler = Locked;
if (handler != null) { Locked(this, args); }
}

Previous example did this
if (handler != null) { handler(this, args); }
instead of...
if (handler != null) { Locked(this, args); }

Thanks, great handbook BTW

mvonballmo wrote  Oct 31 2008 at 5:28 PM  
@pmoriarty: Thanks for the fix! The call in the example is now:

protected virtual void RaiseLocked(EventArgs args)
{
EventHandler handler = Locked;
if (handler != null) { handler(this, args); }
}

emperor_76 wrote  Nov 16 2010 at 3:06 PM  
Excelente :D

vcsekhar wrote  Nov 18 2011 at 10:54 PM  
Thanks for sharing; Could any one, if already present, please also point me to an StyleCop-template built based on this ?

Updating...
Page view tracker