TICS Coding Standard Viewer 
TIOBE Software Quality Framework
Print-friendly version
©TIOBE Software www.tiobe.com
 
C++ Coding Standard
Search

Category: Style

Synopsis:Style and Layout Issues


Description:
This chapter concerns the style or layout of the code. A consistent style increases the readability of the code.

Background information: Operators are operations that are performed, operands are the arguments of these operations. E.g. in "a++", the operator is "++" and the operand is "a". A Unary operator is an operator that has one argument, a binary operator is an operator that takes two arguments. E.g. "<=" and "&&" are binary operators, whereas "!" is a unary operator. A ternary operator is an operator that takes three arguments,e.g. the conditional operator "?".

Coding Rules

NameCheckedSynopsis
STY#001 Checked automatically with code checker The public, protected, and private sections of a class shall be declared in that order
STY#002 Always use parentheses to clarify the order of expression evaluation
STY#003 Use a consistent order in various kinds of class members
STY#004 Checked automatically with code checker Access static members via classes using the :: operator, instead of via objects using the . or -> operator
STY#005 The indentation must be 4 spaces
STY#006 In a class definition use separate public, protected, and private sections for type definitions, constants, enumerations, nested classes, friends, methods and data members
STY#007 Checked automatically with code checker Do not write multiple statements per line
STY#008 Checked automatically with code checker Always write the left parentheses directly after a method/function name
STY#009 Checked automatically with code checker Braces ("{}") which enclose a block are to be placed in the same column, on separate lines directly before and after the block
STY#010 Use the specified method/function declaration and definition layout
STY#011 Checked automatically with code checker In declarations, attach the & or * token to the type name instead of the object name
STY#012 Checked automatically with code checker Do not use spaces around . or ->, nor between unary operators and operands
STY#013 Checked automatically with code checker Do use spaces before and after binary and ternary operators.
STY#014 Checked automatically with code checker Do not use spaces directly before and after brackets
STY#015 Do use spaces after punctuation marks and do not use spaces before punctuation marks
STY#016 Do not use additional parentheses in a return statement
STY#017 Checked automatically with code checker If a method/function has no formal parameter, do not use the keyword void
STY#018 Checked automatically with code checker The keyword typename shall be used to introduce a type parameter to a template
STY#019 Checked automatically with code checker Pointers to pointers should whenever possible be avoided
STY#020 Checked automatically with code checker Use std::function instead of function pointers
STY#021 Do not mix coding styles within a group of closely related classes or within a module
STY#022 Checked automatically with code checker The names of macros are in uppercase
STY#023 The name of a class type used for exceptions is suffixed with _EXC, Exception or Exc
STY#024 Checked automatically with code checker The name of an #include guard shall contain at least the name of the header file.
STY#025 Checked automatically with code checker Do not use letters that can be mistaken for digits, and vice versa
STY#026 When accessing global identifiers, use ::
STY#027 Checked automatically with code checker Do not use tabs in source code
STY#028 Checked automatically with code checker The names of parameters to functions shall be specified in both the function declaration and the function definition
STY#029 Checked automatically with code checker Always provide an access specifier for base classes, data members, and member functions
STY#030 Checked automatically with code checker The keyword struct shall only be used to declare a plain old data struct type
STY#031 Checked automatically with code checker Switch labels and statements should be on seperate lines