Difference between revisions of "RidgeRun Developer Manual/Coding Styles/C++"
(→Conditionals) |
(Fix the NULL to avoid hard typing ambiguities) |
||
Line 13: | Line 13: | ||
*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: | *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 ( | + | if ( nullptr == var ) { |
// ... | // ... | ||
} | } | ||
Line 20: | Line 20: | ||
This is to avoid possible bugs like: | This is to avoid possible bugs like: | ||
<syntaxhighlight lang="c++"> | <syntaxhighlight lang="c++"> | ||
− | if ( var = | + | if ( var = nullptr ) { |
// ... | // ... | ||
} | } |
Revision as of 13:19, 21 December 2020
WORK IN PROGRESS. Please Contact RidgeRun OR email to support@ridgerun.com if you have any questions. |
RidgeRun Developer Manual |
---|
![]() |
Coding Styles |
Development Tools |
Editors |
Debugging Tools |
Methodologies |
Design Patterns |
Testing |
Build Systems |
Contact Us |
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
- Keep the constants at the left side of a comparisons. This applies to all C++ comparison operators. For example:
if ( nullptr == var ) {
// ...
}
This is to avoid possible bugs like:
if ( var = nullptr ) {
// ...
}
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
...
}