Henooh Style Guidelines

Do and Don't - Style Guidelines

Style guidelines lay out a simple method for using case that, when applied consistently, makes things easier to maintain. Many style guidelines does not have better or worse way, it is just simply a matter of taste and preference. However, without set of guidelines, it results in less maintainable code over time. Remember, the purpose of style guidelines is that code should be optimized for the readers, not the writers.

In order to develop reliable and maintainable code, you must follow set of standards. The guidelines in Henooh Framework is written based on experience and referencing various guidelines used in the industry. However, there are numerous standards - and none of them are wrong or bad, main purpose is to select one approach and ensuring that everyone is following it.

It is crucial to write programs that are easy to read and maintain. It is believed that eighty percent of the lifetime cost of a piece of software is spent on maintenance. Also, the turnover of programmers is high, thus it is very likely that more than one person will maintain the code during its lifetime. Whoever inherits your code will appreciate clear and easy-to-read program source code.

Using consistent code guidelines is one way to make the code easier to maintain. Typical style guidelines include filenames, file organization, indentation, comments, delarations, statements, white space and naming conventions.

All henooh software is constantly maintained to follow Microsoft standards, in addition to Henooh standards.

Practice good layout conventions - Set by .NET Framework.

Do.

int a = 1;
int b = 2;
int c = a + b;

Don't. Multiple statements per line, multiple declarations per line.

int a, b, c;
a = 1; b = 2; c = a + b;

Do use 4 spaces per indentation, tabs saved as spaces, indentation per block of code.

public double GetAverageSaturation(Bitmap aBitmap)
{
    for (int y = 0; y < aBitmap.Height; y++)
    {
        // Code
    }
    return averageHue;
}

Don't use other than 4 spaces, tabs, or misaligned indentation.

public double GetAverageSaturation(Bitmap aBitmap)
{
   // 3 Spaces.
    for (int y = 0; y < aBitmap.Height; y++)
        {
            // Proper indentation is one indentation per block
    } // Ughhh, even off alignment
}

Some additional layout conventions for Henooh Framework.

Do!

public Color ReturnColor(Color aValue)
{
    int colorAverage = aValue.Red + aValue.Green +
        aValue.Blue;
}

Don't.

public Color ReturnColor(Color value) {
    Int32 colorAverage = value.Red + value.Green
        + value.Blue;
}

Henooh Framework and var keyword.

Do use var keyword for declaration statements that would be complex.

public class Bingo()
{
    public void CreateBingoCards()
    {
        // Accetpable use
        var bingoCards = new List>>();
    }
}

Don't use var keyword for non-declaration statements that could not be determined in a single line.

public class Bingo()
{
    public void CreateBingoCards()
    {
        var bingoCards = ReadBingoCards();
    }
}

If var keyword seem necessary, look for opportunities to create its own type.

public class CardCell()
{
    public int Number { get; set; }
    public int Called { get; set; }
}

public class BingoCard()
{
    public Dictionary Card { get; set; }
}

public class Bingo()
{
    public void CreateBingoCards()
    {
        var bingoCards = new List();
    }
}

Practice good naming conventions.

Do use good naming practice.

double VelocityOfLightInMetersPerSecond = 299792458;

Don't use underscores to differentiate words, or that matter, anywhere in identifiers.

double velocity_of_light_in_meters_per_second = 299792458;

Don't choose brevity over readability.

double VOfCInMps = 299682458;

Follow the table below for Casing in different type of identifiers.

Please note that Microsoft standards for Parameters are Camel case. But Henooh framework uses a + 'Pascal' for parameters. Although it is not the standard,

Identifier Casing Example
Namespace Pascal
namespace HenoohDeviceEmulator.Native { ... }
Type Pascal
public class KeyboardController { ... }
Interface 'I' + Pascal
public interface IHenoohPeriodicTableDb
Method Pascal
public class BingoCard
{
    internal bool DetermineBingo()
    {
        ...
    }
}
Enum value Pascal
public enum InputType : unit
{
    Mouse = 0, ...
}
Property Pascal
public class Element
{
    public int ElementId { get; set; }
    public int AtomicNumber {get; set; }
}
Event Pascal
public class Timer
{
    public event EventHandler TimerTick;
}
Field Camel
public class HenoohColorIdentifierEngine
{
    internal Color currentRgb = Colors.Black;
}
Parameter 'a' + Pascal
public class HenoohColorIdentifierEngine
{
    public void MoveClick(Point aDestination) { ... }
}

Fields, Properties, Access Modifiers

Don't use fields within a class, use properties instead.

public class HenoohColorIdentifierEngine
{
    Color currentRgb = Colors.Black;
}

Don't omit access modifiers - by allowing it to use default. Explicitly declare all identifiers with the approparate modifier.

public class HenoohColorIdentifierEngine
{
    Color currentRgb { get; set; }
}

Do use C# auto-generation feature to make fields to Properties.

public class HenoohColorIdentifierEngine
{
    private Color currentRgb { get; set; }
}