This link has been bookmarked by 511 people . It was first bookmarked on 29 Jun 2008, by sui seiseki.
-
30 Oct 15
-
26 Jun 14
-
06 May 14
-
Google C++ Style Guide
-
If you are editing code, take a few minutes to look at the code around you and determine its style. If they use spaces around their
ifclauses, you should, too. If their comments have little boxes of stars around them, make your comments have little boxes of stars around them too.
-
-
17 Apr 14
adamsamec- If a variable declared in a for loop is an object, its constructor is invoked every time it enters scope and is created, and its destructor is invoked every time it goes out of scope - so this is not the case with basic data types?
- Static or global variables of class type are forbidden: they cause hard-to-find bugs due to indeterminate order of construction and destruction. However, such variables are allowed if they are constexpr: they have no dynamic initialization or destruction. The constructor code will be called before main(), possibly breaking some implicit assumptions in the constructor code. For instance, gflags will not yet have been initialized. -
15 Apr 14
-
29 Mar 14
-
27 Feb 14
-
02 Feb 14
-
04 Jan 14
-
01 Jan 14
-
28 Nov 13
-
25 Nov 13
-
20 Sep 13
-
31 Aug 13
-
10 Jun 13
-
Another useful rule of thumb: it's typically not cost effective to inline functions with loops or switch statements
-
Preprocessor Macros
-
Inline Functions
-
It is important to know that functions are not always inlined even if they are declared as such; for example, virtual and recursive functions are not normally inlined
-
Usually recursive functions should not be inline.
-
When defining a function, parameter order is: inputs, then outputs.
-
Input parameters are usually values or
constreferences, while output and input/output parameters will be non-constpointers. -
C library, C++ library, other libraries'
.h, your project's.h. -
Within each section the includes should be ordered alphabetically
-
Casting
-
Preprocessor Macros
-
-
29 Apr 13
-
22 Apr 13
-
25 Mar 13
-
prone
-
-
01 Mar 13
-
17 Feb 13
-
20 Jan 13
-
30 Nov 12
-
15 Oct 12
-
15 Aug 12
-
30 Jul 12
-
13 Jul 12
-
11 Jun 12
-
19 May 12
-
18 Apr 12
-
04 Mar 12
-
26 Feb 12
-
09 Jan 12
-
02 Jan 12
-
30 Dec 11
-
18 Dec 11
-
04 Dec 11
-
22 Nov 11
-
06 Oct 11
-
03 Oct 11
-
We do not use
C ++ exceptions.
-
22 Sep 11
-
17 Sep 11
-
07 Sep 11
-
06 Sep 11
-
02 Sep 11
-
29 Aug 11
-
26 Aug 11
-
12 Aug 11
-
02 Aug 11
-
26 Jul 11
-
20 Jul 11
-
18 Jul 11
-
12 Jul 11
-
07 Jul 11
-
29 Jun 11
-
29 May 11
-
29 Apr 11
-
25 Apr 11
-
cpplint
-
Function Comments
-
Function Declarations and Definitions
-
Non-ASCII Characters
-
Formatting
-
Type par_name1, // 4 space indent Type par_name2, Type par_name3) {
-
-
23 Apr 11
-
20 Apr 11
-
14 Apr 11
-
02 Apr 11
-
18 Mar 11
-
11 Mar 11
-
Don't use an
#includewhen a forward declaration would suffice.
-
-
10 Mar 11
-
08 Mar 11
-
28 Feb 11
-
22 Feb 11
-
21 Feb 11
-
10 Feb 11
-
09 Feb 11
-
08 Feb 11
-
28 Jan 11
-
27 Jan 11
-
05 Jan 11
-
21 Dec 10
-
26 Nov 10
-
How can we use a class
Fooin a header file without access to its definition -
We can declare data members of type
Foo*orFoo& -
unctions with arguments
-
parameter order is: inputs, then outputs.
-
outside the class definition
-
static data members
-
you should bring in a definition for
Fooyourself, either via an #include or via a forward declaration -
Define functions inline only when they are small, say, 10 lines or less.
-
You may use file names with a
-inl.hsuffix to define complex inline functions when needed -
to be in a header file
-
se completely global functions rarely
-
For example, accessors and mutators should certainly be inside a class definition.
-
In particular, initialization should be used instead of declaration and assignment
-
Static or global variables of class type are forbidden
-
Rather than creating classes only to group static member functions which do not share static data, use namespaces instead.
-
The order in which class constructors and initializers for static variables are called is only partially specified in C++ and can even change from build to build,
-
unless that function (such as getenv(), or getpid()) does not itself depend on any other globals
-
n general, constructors should merely set member variables to their initial values. Any complex initialization should go in an explicit
Init()method. -
If you must define a nonmember function and it is only needed in its
.ccfile, use an unnamed namespace orstaticlinkage (egstatic int Foo() {...}) to limit its scope. -
consider initializing a pointer (which will never be freed), from either your main() function or from pthread_once().
-
It is always called when calling
new[](for arrays). -
For instance, if you define
Foo::Foo(string name)and then pass a string to a function that expects aFoo, the constructor will be called to convert the string into aFooand will pass theFooto your function for you -
other than access/setting the data members
-
one by directly accessin
-
If your class inherits from an existing class but you add no new member variables, you are not required to have a default constructor.
-
We allow multiple inheritance only when at most one of the base classes has an implementation;
-
with the
Interfacesuffix. -
and you can store pointers rather than objects in an STL container
-
prefer providing a copy method, such as
CopyFrom()orClone(), rather than a copy constructor, -
ncluding the need to reference classes in other namespaces.
-
To do so, add dummy declarations for the copy constructor and assignment operator in the
private: -
In order to ensure that they remain pure interfaces, they must end with the
Interfacesuffix. -
Try to restrict use of inheritance to the "is-a" case
-
destructor
virtual -
Limit the use of
protectedto those member functions that might need to be accessed from subclasses -
that expensive operations are cheap, built-in operations.
-
Do not declare anything in namespace
std -
if a class overloads unary
operator&, it cannot safely be forward-declared. -
In particular, do not overload
operator==oroperator<just so that your class can be used as a key in an STL container -
instead, you should create equality and comparison functor types when declaring the container
-
One case when you might want an input parameter to be a
constpointer is if you want to emphasize that the argument is not copied, -
Every file should have a comment at the top, below the copyright notice and author line, that describes the contents of the file.
-
Do not duplicate comments in both the
.hand the.cc. -
Note that you should never describe the code itself.
-
se only spaces, and indent 2 spaces at a time.
-
eturn type on the same line as function name, parameters on the same line if they fit.
-
-
23 Nov 10
-
06 Nov 10
D CRegular functions have mixed case; accessors and mutators match the name of the variable: MyExcitingFunction(), MyExcitingMethod(), my_exciting_member_variable(), set_my_exciting_member_variable().
Regular Functions
Functions should start with a capitalc++ convention code reference style tutorial google guidelines amazing otimo naming toread
-
01 Nov 10
-
28 Oct 10
-
27 Oct 10
-
16 Oct 10
-
24 Sep 10
-
16 Sep 10
-
14 Sep 10
-
13 Sep 10
-
05 Sep 10
-
01 Sep 10
-
31 Aug 10
Would you like to comment?
Join Diigo for a free account, or sign in if you are already a member.