Skip to content

Coding Style Guide

Ashay Aswale edited this page Mar 18, 2020 · 1 revision

Naming

PascalCased: The name starts with a capital letter, and has a capital letter for each new word, with no underscores.

camelCased: Like CamelCase, but with a lower-case first letter

under_scored: The name uses only lower-case letters, with words separated by underscores. (yes, I realize that

under_scored should be underscored because it's just one word).

ALL_CAPITALS: All capital letters, with words separated by underscores.

If you want to argue on camel vs Pascal case https://www.quora.com/What-is-the-difference-between-Pascal-Case-and-Camel-Case

For python follow PEP-8 standards. If you are using sublime-text you can use autoPEP8 plugin and jedi for auto-completions.

Style guide

  • Classes: PascalCased
// C++
class LeftArmController;
# Python
class LeftArmController:
  • Functions: function name is camelCased and arguments are under_scored
// C++
int setControllerGains(int k_p,int k_i, int k_d);
# Python
def setControllerGains(k_p,k_i,k_d):
  • Variables: under_scored. variable names should be descriptive.
// C++
bool l = false;                 # bad nomenclature 
bool do_you_have_life = false;  # good nomenclature
# Python
do_you_have_life = False
  • Constants: ALL_CAPITALS
// C++
float PI = 3.14;
std::string RGB_IMAGE_TOPIC = "/multisense/camera_image_raw";
# python
PI = 3.14
RGB_IMAGE_TOPIC = "/multisense/camera_image_raw"
  • Global Variables: under_scored with a leading g_
// C++
int g_step_count=0;
# python
_step_count=0

More Info

http://wiki.ros.org/CppStyleGuide

http://wiki.ros.org/PyStyleGuide

Clone this wiki locally