Jump to content

RidgeRun Developer Manual/Coding Styles/C++: Difference between revisions

Line 8: Line 8:


== Good practices ==
== Good practices ==
=== Be consistent with current code ===
In general, if you are adding code to an existent code, be consistent with the coding standard already being used. If no standard is used then follow this guide.
=== Comments ===
* Always use '''/*ANSI-C style comments*/
* Avoid inline comments:
'''Yes:'''
<syntaxhighlight lang="c++">
/*This is a comment*/
if ( NULL == var ) {
  /*...*/
}
</syntaxhighlight>
'''No:'''
<syntaxhighlight lang="c++">
if ( NULL == var ) { /*This is a comment*/
  /*...*/
}
</syntaxhighlight>
=== Use a license and authors header ===
All software need some sort of license and authors documentation, for instance:
<syntaxhighlight lang="c">
/*
*  Copyright (C) 2020 RidgeRun, LLC (http://www.ridgerun.com)
*  All Rights Reserved.
*  Authors: Name Lastname <myemail@something.com>
*          Name Lastmane <otheremail@something.com>
*
*  The contents of this software are proprietary and confidential to RidgeRun,
*  LLC.  No part of this program may be photocopied, reproduced or translated
*  into another programming language without prior written consent of
*  RidgeRun, LLC.  The user is free to modify the source code after obtaining
*  a software license from RidgeRun.  All source code changes must be provided
*  back to RidgeRun without any encumbrance.
*/
</syntaxhighlight>


=== Conditionals ===
=== Conditionals ===
Cookies help us deliver our services. By using our services, you agree to our use of cookies.