- 1、本文档共19页,可阅读全部内容。
- 2、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
Slide1详解
C++ Programming Style /~course/cs101/2014 Hongfei Yan School of EECS, Peking University 11/19/2014 * Outline 目的 书写格式规范 标示符命名规范 文档规范 模块组织规范 一般性原则 目的 增强代码的可读性,从而使得系统具有更少的Bug和更高的健壮性。 * * Outline 目的 书写格式规范 标示符命名规范 文档规范 模块组织规范 一般性原则 书写格式规范 place the brace at the end of the line that controls entry into the block Use a single space to separate the keywords, parentheses, and curly braces in conditional statements. 不使用“hard”TAB White space * 1. place the brace at the end of the line that controls entry into the block * If-else statements: if (condition) { statements; } ? if (condition) { statements; } else { statements; } ? if (condition) { statements; } else if (condition) { statements; } else { statements; } 1. place the brace at the end of the line that controls entry into the block * For-loop statements: for (initialization; condition; update) { statements; } ? An empty for statement should have the following form: for (initialization; condition; update) ; 1. place the brace at the end of the line that controls entry into the block * While statements: while (!done) { statements (); } ? Do-while statements: do { statements; } while (condition); 1. place the brace at the end of the line that controls entry into the block * Switch statements switch (condition) { case ABC : statements; case DEF : statements; break; ? case XYZ : statements; break; ? default : statements; } 2.Use a single space to separate the keywords, parentheses, and curly braces in conditional statements. * (条件语句中,比如if() for() while() try(),使用一个空格分隔关键词,括号和花括号。) for.( ...).{ ? // ... } 3. 不使用“hard”TAB 配置好编辑器,把对齐缩进时敲入的hardTab保存为空格。缩进使用4个空格。 VIM :set tabstop=4 :set expandtab * 4. White space Conventional operators should be surrounded by a space character. C++ reserved words should be followed by a white space. Commas should be followed by a white space. Colons should be surrounded by white space. Semicolons in for statments should be follow
文档评论(0)