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

From RidgeRun Developer Connection
Jump to: navigation, search
m
Line 2: Line 2:
 
{{RidgeRun Developer Manual/Head|previous=Coding Styles/C|next=Coding Styles/Python|keywords=}}
 
{{RidgeRun Developer Manual/Head|previous=Coding Styles/C|next=Coding Styles/Python|keywords=}}
 
</noinclude>
 
</noinclude>
 
  
 
== Introduction to 'C++' Coding Styles ==
 
== Introduction to 'C++' Coding Styles ==
  
 +
There are many coding styles as the concept covers a lot of aspects when writing software source code. In general RidgeRun tries to follow the [https://google.github.io/styleguide/cppguide.html Google C++ Style Guide].
  
 +
== Other good practices ==
  
 +
=== 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:
 +
<syntaxhighlight lang="c++">
 +
if ( NULL == var ) {
 +
  // ...
 +
}
 +
</syntaxhighlight>
  
 
+
This is to avoid possible bugs like:
 
+
<syntaxhighlight lang="c++">
 
+
if ( var = NULL ) {
 
+
  // ...
 +
}
 +
</syntaxhighlight>
  
  

Revision as of 17:31, 21 October 2020




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




Introduction to 'C++' Coding Styles

There are many coding styles as the concept covers a lot of aspects when writing software source code. 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 ) {
  // ...
}



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