GD Coding Guidelines - GreatDevelopers/GreatDevelopers GitHub Wiki

Coding Guidelines

Coding Conventions are essential tool for quality and successful project.

The main goal of these rules and recommendations is to have future software development respect the following criteria:

  • Correctness
  • Maintainability
  • Consistency
  • Readability
  • Comprehensiveness
  • Portability

File Names

File names should be

  • All lowercase, with the extension .h for include files, .c for C source files, and .cpp or C++ source files.
  • Descriptive i.e. reflect the functionality defined/implemented in that file.
  • Use hyphen(-) or underscore(_) to separate words in file name like read-input.h or read_input.cc.

File Header/Description

File header includes description of file name, version, author, license and little information about file.

Use following format:

/**                                                                     
 *       \file       file-name
 *                                                                      
 *       \brief      Description about file
 *                                                                      
 *       \version    1.0
 *       \date       Saturday 23 March 2013 07:20:29  IST
 *       Compiler    g++
 *                                                                      
 *       \author     Author Name, Author's Email ID                 
 *       License     License
 *       \copyright  Copyright (c) 2013, GreatDevelopers                
 *                   https://github.com/GreatDevelopers                 
 */

If you want to add or remove something then you can do that but it should be consistent for all files.

Comments

Comments should be used to give overviews of code and provide additional information that is not readily available in the code itself.

Rules:

  • All comments are to be written in English.
  • All declarations should have a comment indicating the purpose of the declaration.
  • A header file has to contain comments describing class and functions.

Programs can have four styles of implementation comments: block, single-line, trailing, and end-of-line.

Block Comment

/*
 * Here is a block comment.
 */

Single Line Comment

if (condition)
{
    /* Handle the condition. */
    ... 
}

Trailing/ End of line comment

string name;                /* Username */

Indentation

  • Indent using 3, 4, or 8 spaces for each level.
  • Do not use tabs, use spaces. Most editors can substitute spaces for tabs.

Line Length

  • Avoid lines longer than 80 characters, since they're not handled well by many terminals and tools.
  • Line length should be in between 72 and 78 characters.

Naming Conventions

The most important consistency rules are those that govern naming. The style of a name immediately informs us what sort of thing the named entity is: a type, a variable, a function, a constant, a macro, etc., without requiring us to search for the declaration of that entity.

Refer Google Style Guide for naming conventions.