Difference between revisions of "RidgeRun Developer Manual/Coding Styles/C++"

From RidgeRun Developer Connection
Jump to: navigation, search
(Conditionals)
Line 11: Line 11:
 
=== Conditionals ===
 
=== Conditionals ===
  
*Keep the constants at the left side of a comparison. This applies to all [https://en.cppreference.com/w/cpp/language/operator_comparison C++ comparison operators]. For example:
+
*Keep the constants at the left side of a comparisons. This applies to all [https://en.cppreference.com/w/cpp/language/operator_comparison C++ comparison operators]. For example:
 
<syntaxhighlight lang="c++">
 
<syntaxhighlight lang="c++">
 
if ( NULL == var ) {
 
if ( NULL == var ) {

Revision as of 17:37, 21 October 2020




Previous: Coding Styles/C Index Next: Coding Styles/Python




Introduction to 'C++' Coding Styles

When writing software source code there are many coding styles as the concept covers a lot of aspects (some of them subjective). In general RidgeRun tries to follow the Google C++ Style Guide.

Other good practices

Conditionals

if ( NULL == var ) {
  // ...
}

This is to avoid possible bugs like:

if ( var = NULL ) {
  // ...
}

A derived good practice is to use const keyword as much as you can:

const int val = 1;

if (val = 2) { // This should not compile
    ...
}


Previous: Coding Styles/C Index Next: Coding Styles/Python