没有合适的资源?快使用搜索试试~ 我知道了~
首页C++ 代码规范(英文版)
资源详情
资源评论
资源推荐
C++ Coding Standards
The Corelinux Consortium - Revision 1.6
Abstract:
This document describes the C++ Coding Standards as they are used in the
corelinux++ project. It provides a set of guidelines, rationales and
standards for C++ coding.
Contents
Scope
o Document Overview
General Principles
Comments
Code Layout
o Braces and Parenthesis
o Declarations
o Keyword Constructs
o Preprocessor
o Spaces
o Wrapping
Naming Conventions
o Files and Directories
Usage
o Conditionals
o Loop Constructs
o Data
o Constructors and Destructor
o Initialization
o Declaration
o Programming
o Class and Functions
o Templates and Template Functions
o Inheritance
o Object-Oriented Considerations
o Error Handling
o Exception Specification
File Layout
o Header File Layout
Linux Special Care and Handling
1
Bibliography
Copyright notice
CoreLinux++ Copyright (c) 1999, 2000 CoreLinux Consortium
Revision 1.6 , Last Modified: 2000/09/22
This material may be distributed only subject to the terms and conditions set
forth in the Open Publication License.
Scope
The principle function of this document is to establish a consistent standard
which will provide for easier maintenance of code. This will benefit the team
and the project in that those who are new to the code can quickly orient
themselves, and thereby sooner become productive members of the team. It
is intended to be a dynamic document and can be reviewed as needed. It is
recommended that each programmer keep a copy on hand also.
Document Overview
The following document sections contain standards, guidelines, and
rationales. Guidelines must be adhered to unless there is compelling reason
to deviate. Deviation from a guideline must be discussed and approved during
the code walk-through. A standard is an item to which compliance is
mandatory. Deviation from a standard must be discussed, approved, and
signed-off on by the team lead during the code walk-through. Rationales have
been used where necessary to explain the meaning of an item, or why it was
chosen.
General Principles
This section contains the basic philosophy a developer should keep in
mind while coding.
Comments
This section deals with the placement and contents of comments in the
code.
Code Layout
This section has to do with the alignment of the code, white space,
declarations and keywords, and where they should all be located.
Naming Conventions
This section contains the structure for naming classes, functions, files,
and directories.
Usage
2
This section concerns the 'how' and 'when' certain constructs should be
used (for example, loops, inheritance, error handling, etc.)
File Layout
This section applies to where things should be located in header files
and modules.
Coding Examples
This section contains an example of a header file and module which
conform to the C++ Coding Standard.
General Principles
The primary goal of the coding standard is maintainability. Other important
considerations that relate to the spirit of the standard includes correctness,
readability, consistency, extensibility, portability, clarity, and simplicity. When
in doubt, the programmer should strive for clarity first, then efficiency.
Think of the reader. Do not just write for yourself. Keep it simple. Break down
complexity into simpler chunks. Clearly comment necessary complexity. Be
explicit. Avoid implicit or obscure language features. Be consistent. Minimize
scope, both logical and visual.
Comments
Guideline 1: Be clear and concise. Say what is happening and why. Do not
restate code.
Guideline 2: Keep code and comments visually separate.
Standard 1: Use top of file comments for all files.
Standard 2:Use header comments for all functions. The size of the comment
should mirror the size and complexity of the code. Class interface functions
and procedures should be commented in the header.
Standard-HPP 1: Use JavaDoc commenting style (/// and /** ...*/) . We will
use an HTML generator tool to produce class library documentation.
namespace corelinux
{
DECLARE_CLASS( SomeClass );
/**
Main documentation for the class appear after
namespace and any type or
class macros and above the actual class declaration.
Unless of course it is NOT a CoreLinux++ class.
*/
3
class SomeClass
{
};
}
for methods
/**
Explanation of method
@param Type modifier optional summary
@return Type modifier @exception
Type [,Type]
*/
-or-
/// Destructor
for members
/// Single line primarily for data members
}
Standard-CPP 1:Use only the C++ comment style (double slashes) for single
line comments.
Guideline 3: For block comment styles either C++ (double slashes) or C
style (/* ... */) can be used.
// ...
-OR-
// // ... //
-OR-
/* ... */
Standard 3:The trailer comment should only include configuration
management information defined as:
/*
Common rcs information do not modify
$Author: frankc $
$Revision: 1.6 $
$Date: 2001/01/01 13:39:18 $
$Locker: $
*/
4
Guideline 4: Prefer block comments over trailing comments. Use block
comments regularly. Only use trailing comments for special items.
Standard 4: Trailing comments must all start in the same column in the
function.
Standard 5: Trailing comments at a closing brace are indented one level from
brace.
Standard 6: Block comments are at the same indentation level as the block
they describe.
Standard 7: Ensure comments are correct (and stay correct).
Code Layout
Guideline 5: Write code in a series of chunks.
Guideline 6: Use block comments to separate the chunks.
Standard 8: Put one statement per line, except with in-line code in a header
file.
Guideline 7: Functions shall have a single exit point.
Rationale: Multiple exit points usually add to the complexity of a function. Post
conditions and invariant checks must also be performed prior to each return.
Standard 9: Indentation level is three (3) spaces.
Braces and Parenthesis
Standard 10: Braces shall be aligned using Ulman style where the braces
are at the same scope as the statement that proceeds them and the code
within the braces is indented one level. Braces are always on a line by
themselves.
void doSomething( void )
{
if( x != y )
{
y = x;
}
else
{
; // do nothing
}
}
-NOT-
void doSomething( void )
5
剩余35页未读,继续阅读
a1073710317
- 粉丝: 4
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 收起
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
会员权益专享
最新资源
- stc12c5a60s2 例程
- Android通过全局变量传递数据
- c++校园超市商品信息管理系统课程设计说明书(含源代码) (2).pdf
- 建筑供配电系统相关课件.pptx
- 企业管理规章制度及管理模式.doc
- vb打开摄像头.doc
- 云计算-可信计算中认证协议改进方案.pdf
- [详细完整版]单片机编程4.ppt
- c语言常用算法.pdf
- c++经典程序代码大全.pdf
- 单片机数字时钟资料.doc
- 11项目管理前沿1.0.pptx
- 基于ssm的“魅力”繁峙宣传网站的设计与实现论文.doc
- 智慧交通综合解决方案.pptx
- 建筑防潮设计-PowerPointPresentati.pptx
- SPC统计过程控制程序.pptx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论1