Naming Cases
Item | Description | Example |
Pascal case | First letter of every word is capitalized with no spaces or symbols between words | AudioControlManager |
Camel case | Starting with a lower case, first letter of every word is capitalized with no spaces or symbols between words | findMaxScore() |
Lower snake case | Words within phrases or compound words are separated with an underscore; all lower case | number_of_retries |
Upper snake case | Words within phrases or compound words are separated with an underscore; all upper case | NUMBER_OF_RETRIES |
Naming Conversion for C++
Item | Rule | Example |
File | 1. One primary class, one file (.cpp + .h) 2. Put declaration in .h and implementation in .cpp 3. If declaration and implementation are at the same place (usually template), put them into .hpp 4. File name is the same as primary class name 5. For file with 'main()', file name can be "main_" + "executable name".cpp | MediaPlayer.cpp MediaPlayer.h TNotificationCentrer.hpp main_lcm.cpp |
Class | 1. Interface class: "I" + pascal case 2. Template class: "T" + pascal case 2. Normal class/Structure: Pascal case | class ConnectionManager; |
Member function | Camel case; usually first word is verb | void getTimeofDay(); |
Member variable | "m" + Pascal case | int32_t mRefCount; |
Typedef type | Pascal case | typedef ConnectionManager ConnMgr; |
Enumeration | type name: Pascal case value: all upper case and "_" | enum ProcessResult { SUCCESS, FAIL }; |
Name space | Lower snake case | using namespace bosch::housekeeping; |
Local variable | Lower snake case | void getPlaybackInfo() { std::string artist_name; uint32_t current_time; uint32_t total_time; } |
Global variable | "g" + Pascal case | ConnectionManager gConnMgr; |
Static variable (Non-member variable) | "s" + Pascal case | static void sLogContext; |
Static function (Non-member function) | Lower snake case; usually first word is verb | static void sort_by_name(PhoneBook &pb) |
Integer type | using <cstdint> | uint32_t, int32_t, uint16_t… |
cross platform | perfer C++11 | <thread>, <mutex>, <random>, <condition_variable>… |
Source code beautifer | astyle (support C, C++, C++/CLI, Objective‑C, C# and Java) |
Naming Conversion for Protobuf IDL
Item | Rule | Example |
File | 1. Naming style: Lower case separated by '.' 2. Naming rule: "Fdbus server name" + optional texts + ".proto" | hosusekeeping.lcm.proto |
Fdbus server | 1. Naming style: Lower case separated by '.' 2. Naming rule: "" + server name | hosusekeeping.lcm |
package | 1. Naming style: the same as name space 2. Naming rule: name space of the server + ".pb" | package .housekeeping.lcm.pb |
message | 1. message name: Pascal case 2. member name: Lower snake case | message DisplayStatus { uint32 back_light = 0; } |
Enumeration | 1. type name: pascal case 2. value name: upper snake case | |
FDBus Message ID | 1. Naming style: Upper snake case 2. Naming rule: "MSG_" + message name | enum FdbusMessageId { MSG_GET_CONTACT_NAME = 0; //MessageName } |
FDBus Event ID | 1. Naming style: Upper snake case 2. Naming rule: "EVT_" + message name | enum FdbusEventId { EVT_GET_CONTACT_NAME = 0; //Message Name } |
File Header (for C/C++/proto source file and head file)
/**
* @swcomponent
* @{
* @file XXXX.cpp
* @brief This Cpp file defines Implementation of the Class XXXX
* @copyright (C) 2019 .
* The reproduction, distribution and utilization of this file as
* well as the communication of its contents to others without express
* authorization is prohibited. Offenders will be held liable for the
* payment of damages. All rights reserved in the event of the grant
* of a patent, utility model or design.
* @}
**/
Class Comments
/**
* <Long Description>
*/
Method Comments
/**
* <Long description>
*
* @param[i] <name> <description>
* @param[o] <name> <description>
* @param[io] <name> <description>
* @return <description>
* @throw <typename of exception>
*
* @pre <pre-condition before calling this method>
* @post <post-condition after calling this method>
* @bug <known issue>
*/
void getServiceName()
Member Comments
/** <Short Description> */
int32_t name;
使用4个空格代替TAB键。