WebKit代码规范

WebKit代码规范

ID:39469775

大小:64.00 KB

页数:11页

时间:2019-07-04

WebKit代码规范_第1页
WebKit代码规范_第2页
WebKit代码规范_第3页
WebKit代码规范_第4页
WebKit代码规范_第5页
资源描述:

《WebKit代码规范》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库

1、WebKit代码规范缩进1.使用空格而不是Tab。Tab只应该出现在有语义的文件里,如makefile文件。2.缩进大小为4个空格。正确: int main() {     return 0; }错误:int main() { return 0; }3.在头文件中,命名空间中的代码应该被缩进。正确: //Document.h namespace WebCore {   class Document { Document(); ... };   } //namespaceWebCore错误://Do

2、cument.h   namespace WebCore { class Document {  Document();  ...  };   } //namespaceWebCore4.在实现文件中,命名空间中的代码不应该缩进。正确: //Document.cpp namespace WebCore { Document::Document() { ... } } //namespaceWebCore错误://Document.cpp namespace WebCore {  Document:

3、:Document() { ... }   } //namespaceWebCore1.case标签应该和switch对齐,case下的语句要缩进。正确: switch (condition) { case fooCondition: case barCondition: i++; break; default: i--; }错误:switch (condition) { case fooCondition: case barCondition: i++; break; default: i--;

4、 }2.当同一层面的布尔表达式跨多个行时,布尔操作符应该放在行首而不是后面。正确: return attr->name() == srcAttr 

5、

6、 attr->name() == lowsrcAttr 

7、

8、 (attr->name() ==usemapAttr && attr->value().domString()[0] != '#');错误:return attr->name() == srcAttr 

9、

10、 attr->name() ==

11、 lowsrcAttr 

12、

13、 (attr->name() ==usemapAttr && attr->value().domString()[0] != '#');空格1.一元操作符前不加空格。正确: i++;错误:i ++;1.二元与三元操作符前后应该加上空格。正确: y = m * x + b; f(a,b); c = a 

14、 b; return condition ? 1 : 0;错误:y=m*x+b; f(a,b); c = a

15、b; return condit

16、ion ? 1:0;2.控制语句与圆括号之间要加空格。正确: if (condition) doIt();错误:if(condition) doIt();3.函数调用时,函数名和圆括号之间、圆括号与其内容之间不留空格。正确: f(a,b);错误:f (a,b); f( a,b );换行1.每个语句占用一行。正确: x++; y++; if (condition) doIt();错误:x++; y++; if (condition) doIt();2.else关键字应该和前面大括号在一行。正确: i

17、f (condition) { ... } else { ... }错误:if (condition) { ... } else { ... }3.当前一个if语句被return语句终止时,elseif语句应该写成多个if语句的形式。正确: if (condition) { ... return someValue; } if (condition) { ... }错误:if (condition) { ... return someValue; } else if (condition) { .

18、.. }大括号1.行数定义:每个大括号占用一行。正确: int main() { ... }错误:int main() { ... }2.其它大括号:左括号放在前一条语句之后,右括号单独占用一行。正确: class MyClass { ... };   namespace WebCore { ... }   for (int i = 0; i < 10; i++) { ... }错误:class MyClass { ... };3.仅有一行的条件控制语句不使用大括号。正确: 

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。