Skip to content

Coding Style

Aman Priyadarshi edited this page Mar 12, 2017 · 10 revisions

The article describes general coding style guidelines, which should be used for Atom code. These guidelines apply exclusively to C# source files.
As much existing AtomOS code as possible should be converted to this style. Make sure you mark your progress on Styling Issue.

File Structure

  • Every AtomOS source code file should include a file header like this:
/*
* PROJECT:          Atomix Development
* LICENSE:          BSD 3-Clause (LICENSE.md)
* PURPOSE:          File Description
* PROGRAMMERS:      Your Name (Your Email ID)
*/

You may add yourself to the PROGRAMMERS section of a file if you did a major contribution to it and could take responsibility for the whole file or a part of it.

  • Using section of C# file should follow these guidelines
    1. No unused block.
    2. Internal namespace should come before external namespaces.
    3. Internal namespaces and external namespaces should be separated by a new line.

Indentation

  • Indent with tabs, don't use spaces!
  • Editor Configuration File

Braces

  • Always put braces ({ and }) on their own lines.

  • One-line control clauses should not use braces.

    Right:

    if (condition)
       DoSomething();
    if (condition)
    {
       DoSomething();
       DoSomethingElse();
    }
    

    Wrong:

    if (condition) {
       DoSomething();
    }
    if (condition)
    {
       // note, one liner clause should not have braces
       DoSomething();
    }
    

Naming

  • Naming convention should follow CamelCase.

  • Precede Boolean values with meaningful verbs like "is" and "did" if possible and if it fits the usage.

    Right:

    bool IsValid;
    

    Wrong:

    bool Valid;
    
  • Prefix Method Parameters with 'a' and non-public non-static class fields with 'm'.

Spacing

  • Space after if/while/do.
  • No spacing after method name of identifier or array modifier.

Commenting

  • Avoid line-wasting comments

  • Leave space after forward slash.

    Right:

    // Allocate memory for future heap manager
    // Find a suitable hole
    

    Wrong:

    //Allocate memory for future heap manager
    //Find a suitable hole
    
Clone this wiki locally