Coding StandardsFor either a team or individual to develop clean, consistent and easily maintained codean agreement to a set of coding standards should be made by all developers. I personally try to adhere to the following standards:
|
| I use the following C# class template. |
//---------------------------------------------------------
//
// FILE: apple.cs
// CLASSES: Apple
//
// AUTHOR: Bill Daniels
// Copyright (c) 2011,
// D+S Tech Labs, Inc.
// All Rights Reserved
//
// USAGE: ...
//
// NOTES: ...
//
//---------------------------------------------------------
using System;
using System.Windows;
using System.Windows.Controls;
//---------------------------------------------------------
// CLASS: Apple
// PARENT: Fruit
//---------------------------------------------------------
public class Apple : Fruit
{
//--- Types/Constants -----------------------------------
(enums, etc.)
(const, etc.)
//--- Data ----------------------------------------------
public string Color; // public member start with upper case letter
protected int size; // non-public members start with lower case letter
//--- Properties ----------------------------------------
public int Size // property names should be initial capped version of protected member
{
get
{
...
return size;
}
set
{
...
size = value;
}
}
//--- Constructor ---------------------------------------
public Apple (...)
{
...
}
//--- Destructor ----------------------------------------
public ~Apple ()
{
...
}
//--- Method1 -------------------------------------------
public void Method1 ()
{
...
}
//--- Method2 -------------------------------------------
public void Method2 ()
{
...
}
}
|
|
I also line-up common attributes and equal signs in my code. It's just easier to read and maintain. These two chunks are the same. |
public int TotalAdjustments = 0;
protected Label prompt = new Label ();
protected ListView[] reportLists = new ListView[4];
private float customerEarnings = 0.0F;
public int TotalAdjustments = 0;
protected Label prompt = new Label ();
protected ListView[] reportLists = new ListView[4];
private float customerEarnings = 0.0F;
|