您的位置:首页 > 编程语言 > C语言/C++

C++ coding style (for webkit)

2014-04-09 10:11 295 查看
Rename parameter definition according webkit’s renaming style:

1) Use CamelCase. Capitalize the first letter, including all letters in an acronym, in a class, struct, protocol, or namespace name. Lower-case
the first letter, including all letters in an acronym, in a variable or function name.

2) Use full words, except in the rare case where an abbreviation would be more canonical and easier to understand.

3) Data members in C++ classes should be private. Static data members should be prefixed by "s_".Other data members should be prefixed by "m_".

4) Prefix Objective-C instance variables with "_".

5) Precede boolean values with words like "is" and "did".

6) Precede setters with the word"set". Use bare words for getters. Setter and getter names should match the names of the variables being set/gotten.

7) Precede getters that return values through out arguments with the word "get".

8) Use descriptive verbs in function names.

9) Leave meaningless variable names out of function declarations. A good rule of thumb is if the parameter type name contains the parameter name (without
trailing numbers or pluralization),then the parameter name isn't needed. Usually, there should be a parameter name for bools, strings, and numerical types.

10) Prefer enums to bools on function parameters if callers are likely to be passing constants, since named constants are easier to read at the call site.
An exception to this rule is a setter function, where the name of the function already makes clear what the boolean is.

11) Objective-C method names should follow the Cocoa naming guidelines — they should read like a phrase and each piece of the selector should start with
a lowercase letter and use intercaps.

12) Enum members should use InterCapswith an initial capital letter.

13) Prefer const to #define. Prefer inline functions to macros.

14) #defined constants should use all uppercase names with words separated by underscores.

15) Macros that expand to function calls or other non-constant computation: these should be named like functions,and should have parentheses at the end,
even if they take no arguments (with the exception of some special macros like ASSERT). Note that usually it is preferable to use an inline function in such cases instead of a macro.

16) #define, #ifdef "headerguards" should be named exactly the same as the file (including case),replacing the '.' with a '_'.

And the Webkit coding stype link : http://www.webkit.org/coding/coding-style.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: