几个简单代码片段-- Google C++ style guide
欧洲杯,德国VS意大利。战车遇到浪漫之师,结果如何?
Who Cares!!!
开球之前,review一下近期写的代码,发现一些代码写的不是很规范。于是,重新温习一下 Google C++ style guide。
之前博客有过介绍,谷歌C++编程规范笔记,现在只是用几个简单的代码片段展示一下。
定义常量、宏定义、枚举:
// 使用下划线分隔
#define FLAG_FOO 0x0// 要有括号
#define FLAG_BAZ (0x1 << 3)// 对于常量,使用k
const int kStateFoo = 0;typedef struct linked_list LinkedList;// 枚举跟宏定义类似
typedef enum {MODE_FOO,MODE_BAR,MODE_BAZ,MODE_QUX
} Mode;// 枚举也可以像常量一样
typedef enum {kStateFoo,kStateBar,kStateBaz,kStateQux
} State;typedef struct sample {int first_field;bool second_field;Mode mode;State state;struct sample *next;
} Sample;
函数:
//注意第一个大括号的位置
bool SampleEqual(Sample *self, Sample *other) {// Local variables are lower_case and separated by underscores.if (self == NULL && other == NULL) {return true;}if (self == NULL || other == NULL) {return false;}//多行if (self->first_field == other->first_field &&self->second_field == other->second_field &&self->state == other->state &&self->mode == other->mode &&self->next == other->next) {return true;}return false;
}//多个参数
Sample *SampleNew(int first_field,bool second_field,Mode mode,State state,Sample *next) {Sample *sample = (Sample *) malloc(sizeof(*sample));if (sample == NULL) {return NULL;}memset(sample, 0, sizeof(sample));sample->first_field = first_field;sample->second_field = second_field;sample->mode = mode;sample->state = state;sample->next = next;return sample;
}Sample *SampleClone(Sample *sample) {if (sample == NULL) {return NULL;}return SampleNew(sample->first_field,sample->second_field,sample->mode,sample->state,sample->next);
}static void SampleDoSomethingWithALongName(Sample *sample,int parameter_with_a_long_name,bool another_parameter,int another_parameter) {if (sample == NULL) {return;}bool local_variable;if (parameter_with_a_long_name == kStateFoo) {local_variable = true;} else {local_variable = false;}sample->first_parameter += another_parameter;sample->second_parameter |= local_variable;
}
几个简单代码片段-- Google C++ style guide相关推荐
- Google cpp style guide 之 include
首先是传送门: Google cpp style guide: http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml 中文版:( ...
- Google Python Style Guide(谷歌python规范指南)
来自:Google Python Style Guide 1. 背景 Python是谷歌内部使用的主要动态语言(脚本语言).这份指导手册列出了使用Python的编程人员应该做的和不应该做的. 为了帮助 ...
- Google C++ Style Guide - Google C++ 风格指南
Google C++ Style Guide - Google C++ 风格指南 Every major open-source project has its own style guide: a ...
- Google Objective-C Style Guide
看题目就知道了-哪天有空翻译成中文的-不多说了-上链接- Google Objective-C Style Guide 转载于:https://blog.51cto.com/lulala/659124
- Google JavaScript Style Guide
转自:http://google.github.io/styleguide/javascriptguide.xml Google JavaScript Style Guide Revision 2.9 ...
- DIEA ,Ecplise 配置谷歌代码风格 Google Java Style
我是陈皮,一个在互联网 Coding 的 ITer,微信搜索「陈皮的JavaLib」第一时间阅读最新文章,回复[资料],即可获得我精心整理的技术资料,电子书籍,一线大厂面试资料和优秀简历模板. 目录 ...
- PEP8-python代码样式指南(Style Guide for Python Code)
文章目录 介绍(Introduction) 尽信书不如无书(A Foolish Consistency is the Hobgoblin of Little Minds) 代码布局(Code Lay- ...
- [简单]代码片段_3
下面的代码很简单,替换参数功能很早前有人写过,而且写的还不错,直接贴代码. import java.io.FileOutputStream; import java.util.ArrayList; i ...
- Google Python Style Guide
https://google.github.io/styleguide/pyguide.html 转载于:https://www.cnblogs.com/bettyty/p/6357323.html
最新文章
- 大连理工计算机专业导师,大连理工大学计算机科学与技术学院研究生导师简介-申彦明...
- mfc只有doc才能序列化吗_MFC序列化-IMPLEMENT_SERIAL(...)
- asp.net母板使用注意
- python可以自学吗-python能够自学吗
- Linux下如何可写挂载ntfs分区
- 【BZOJ3958】[WF2011]Mummy Madness 二分+扫描线+线段树
- m3u8手机批量转码_手机怎么把m3u8格式转换成mp4格式?
- 铁路专用计算机,浅谈专用铁路计算机联锁控制
- 11-Container With Most Water
- MySQL选择合适的数据类型
- 笔趣阁 单篇小说采集
- 几种开放源码的TCPIP协议栈
- 西门子触摸屏脚本程序_西门子触摸屏实例程序
- 基金会总线协议分析(FF协议)
- 支付宝当面付_小小的支付完成页上,微信和支付宝“打起来了”
- 论文阅读笔记:《EIGENGAME: PCA AS A NASH EQUILIBRIUM》(特征博弈:主成分分析就是纳什均衡)
- Python+ASAquick+PSIPred蛋白质序列特征计算,ASAquick安装调用(Linux)
- 面试了几十家软件测试公司全是这个“套路”
- 一步步带你了解分布式数据库的架构演变之路!
- 通过继承实现圆柱体面积体积的计算
热门文章
- 物流管理系统之数据仓库实现(二)
- 关于Python发帖机
- [编程开发工具-6]:github仓库、gitee仓库、git本地仓库混合管理的架构与详细实现步骤
- 分享BlueStacks蓝手指安卓模拟器
- 微信:支付验证签名失败
- 【Numerical Optimization】17 Penalty and Augmented Lagrangian Methods
- 《智慧城市时空大数据平台建设技术大纲(2019版)》解析——未完,待续
- 上海交大软件工程专业不读,跑去井冈山大学?
- fanuc机器人刷机教程_(完整版)FANUC机器人基本操作指导
- 小程序模拟大巴车在线选择座位