Skip to content

Latest commit

 

History

History
112 lines (94 loc) · 2.26 KB

Source_code_drawing_up.md

File metadata and controls

112 lines (94 loc) · 2.26 KB

Drawing up the source code

This document is brought to pinpoint the rules of code's drawing up, in order to keep its unified style and to raise its readability.

  • Instead of tabulation, 4 blank spaces are used for indentation in the code.

  • The end of line is assigned in unix format(LF).

  • In case the file contains a class definition, it is to be named as following: %ClassName%.hpp %ClassName%.cpp. Elsewise, all letters in the file name have to be lower case (small):

SpeedTest.hpp
SpeedTest.cpp
version.hpp
  • All values start with lower case letter:
QString filePath;
  • All function names also start with lower case letter:
const QString & getFilePath();
  • Global values are named with the prefix g%varName% :
int gDebugLevel;
  • Class values are named with the prefix _%varName%:
uint8_t _buff;
  • Classes names start with upper case (capital) letter:
class Man
{
public:
        Man();
private:
        int _height;
        int _age;
}
  • Name spaces are written in lower case characters:
namespace lightpack
{
}
  • Constants are named starting with upper case letter with the prefix k:
const int kFirstLetterCapital;
  • Using #define in C++ code is not recommended. In case of a pressing need in name, all symbols must be upper case:
# define ALL_CAPITAL_LETTERS
  • Gaps after if, for, while, and other key words:
if (first == second)
{
    for (int i = 0; i < N; i++)
        doSomething();
    while (condition)
        doSomethingElse();
} else {
    findCallbackFunction();
}

  • In case of a single statement in all branches, round brackets can be dropped:
if (first == third)
        start();
else
        stop();
  • In header files the control directive should be used in order to eliminate collisions:
# pragma once
  • Name spaces are written down without gaps:
namespace lightpack
{
namespace speedtests
{
        class AnotherMan
        {
        }
}
}
  • When using comments with TODO markup in the code, it's desirable to describe precise author's intentions:
int getAvgColor()
{
        // TODO: come up with a very fast algorithm for calculating the average color
        return -1;
}