【代码规范】Google C++开源风格指南

参考地址

https://zh-google-styleguide.readthedocs.io/en/latest/contents/

常用清单

命名类

  1. 变量名全部小写,不需要类型前缀: int counts = 0;
  2. 函数名单词开头大写: RunFunction();
  3. const/enum 类型加k , 单词开头大写: kCountNum
  4. 舍弃掉全大写(TEST_DEFINE)这类宏定义命名方式

类型转换方式

禁止使用强转风格:int a = (int)b

  1. static_cast
  2. reinterpret_cast
  3. dynamic_cast

格式类

  1. 把tab调为2个空格字符
// bad
{
    int a = 0;
}

// better
{
  int a = 0;
}
  1. 不要无效空行
// bad
int a = 0;
if(true) {
  a = 1;

}

a = 2;

// better
int c = 0;
if(true) {
  c = 1;
}

c = 2;
posted @ 2019-07-16 14:53  鱼汤泡饭  阅读(455)  评论(0编辑  收藏  举报