编程规范:命名和规则

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键。 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

AllenSun-1990

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值