Coding Guidelines

From Ultimate Commander

You should follow the holy guidelines outlined in this document to keep the code beautiful and don't be burned in hell.

Contents

General Code Layout

- Order your code in your source files, like this:

using <standard namespaces>
using <unix namespaces>
using <gtk and gnome namespaces>

namespace UltimateCommander {

    private class PrivateClass1 {

        ...
    }

    other private class definitions

    public class PublicClass1 {

        constants

        static members

        glade widgets

        other data members

        constructors

        destructor

        public methods

        public properties

        utility methods

        signal handlers
    }
}

Tagging buggy code

If there is a bug in your implementation tag the problem by using the word "FIXME" in the code, together with a description of the problem.

Do not use XXX, TODO or obscure descriptions, because otherwise people will not be able to understand what you mean.

Line length and alignment

- Line length: The line length for C# source code is 100 columns.

If your function declaration arguments go beyond this point, please align your arguments to match the opening brace, like this:

void SomeMethod(int FirstArg, float SecondArg,
                string ThirdArg)
{
    ...
}

When invoking functions, the rule is different, the arguments are not aligned with the previous argument, instead they begin at the tabbed position, like this:

string iconname = Gnome.Icon.Lookup(new Gnome.IconTheme(), null, "", null,
                                    new Gnome.Vfs.FileInfo (), MimeType,
                                    Gnome.IconLookupFlags.None, out result_flags);

Indentation

- Use 4 space characters for identation, not tabs.

- Switch statements have the case at the same indentation as the switch:

switch (x) {
case 'a':
	...
case 'b':
	...
}

Where to put spaces

- Do not put any spaces before an opening parentheses or between parantheses when calling functions, or indexing. This is correct:

MethodName(a);
array_name[10];

However use a space before the opening parantheses of conditionals and control structures, like this:

for (i=0; i<10; i++) {
    if (something(i)) {
        do_more();
    }
}

- Always put a space after a comma.

- Use white space in expressions liberally, except in the presence of parenthesis, like this:

if (a + 5 > method (blah () + 4))

Where to put braces

- Always use braces for code blocks even when they are not necessary:

if (condition) {
    MethodName();
}

- Inside a code block, put the opening brace on the same line as the statement and the closing brace of a separate line:

if (code) {
    MethodName1();
    MethodName2();
}

- When defining a method, use the C style for brace placement, that means, use a new line for the brace, (even in the case of empty methods) like this:

void Method()
{
}

- Properties and indexers are an exception, keep the brace on the same line as the property declaration, like this:

int Property {
    get {
        return value;
    }
}

- for very small properties, you can compress things:

int Property {
    get { return value; }
    set { x = value; }
}

- Namespace, Class, braces on the same line and separate them with an empty line, like this:

namespace Foo {

    public class Bar {

        private void Method()
        {
            if (condition) {
                ...
            }
        }
    }
}

Naming identifiers

- Method, property and namespace names should be written with CamelCase.

- Private variable names should be written with lower_case_with_under_scores.

- Signal handler method names should be written as "On" + FullWidgetName + ActionName, like OnSuperNiftyButtonToggled.

Semantic guidelines

- Do no use public variables in public classes. Make private variables accessible with public accessors in public classes instead.


Log in / create account
Google
 

This page was last modified on 13 March 2006, at 23:27.
Mono powered Powered by MediaWiki SourceForge.net Logo Valid XHTML 1.0 Transitional Valid CSS!