From e33361fcd369c2009d7db0e30413c3ee5f50f4ce Mon Sep 17 00:00:00 2001
From: "mark@chromium.org"
Date: Fri, 4 Nov 2011 16:55:22 +0000
Subject: [PATCH] Update C++ style guide to 3.199: - Update an example to omit
the blank line between C and C++ #includes. - Rewrite the paragraph about
#include ordering. - Clarify namespace closing comments. - Discourage const
references for input arguments which are aliased beyond the scope of the
function call. - Replace all '&' with '&'. - Clarify that interfaces
must have virtual destructors. - Add an explicit example for |else if|. -
C++11 updates.
Update Objective-C style guide to 2.36:
- Remove requirement to list @dynamic implementations.
- Remove requirement to never synthesize CFType properties, since they may
be retained on 10.6.
- Use __weak and __strong type declaration modifiers rather than comments.
- Make the copyright/license information consistent.
- An example initializer comment revealed too much about the implementation.
- Correct spelling mistakes.
- Fix names that didn't follow Cocoa conventions.
- Fix examples to conform to style.
- Add a section about no braces for empty interfaces.
- Add a section about automatically synthesized instance variables.
- Codify avoidance of accessors in -init and -dealloc methods.
- Changes for the 80-column rule.
- Weaken the language around object ownership type qualifiers.
- Document the rules for formatting blocks.
Update JavaScript style guide to 2.27:
- Introduce EcmaScript 5 Strict verbiage.
- Add a note about private constructors.
- Simplify explanations about JSDoc comments.
- Sort the JSDoc tags.
- Remove the sections about type-checking now that the JSDoc tags and JS
types are no longer one table.
- Convert to
-Revision 3.188
+Revision 3.199
, because the XSL processor eats .
- Add @suppress.
- Mark @inheritDoc deprecated in favor of @override.
- Add a section about inner classes and enums being defined in the same file
as the top-level class they are defined on.
Update Python style guide to 2.28:
- Change "Naming" summary to match body.
- Make the prohibition against backslash line continuation explicit.
- Update the TODO section to match the C++ style guide.
- Declare Python code without a shebang line to be stylish.
- Clarify rules on function docstrings.
- Fix spelling errors.
- Update with styleguide.xsl 1.33.
Update styleguide.xsl to 1.33:
- Clean up style guide JS.
- Links to anchor tags auto-expand.
---
cppguide.xml | 83 ++-
javascriptguide.xml | 1649 +++++++++++++++++++++----------------------
objcguide.xml | 435 ++++++++----
pyguide.html | 357 ++++++----
styleguide.xsl | 120 ++--
5 files changed, 1432 insertions(+), 1212 deletions(-)
diff --git a/cppguide.xml b/cppguide.xml
index a3e45c2..480876c 100644
--- a/cppguide.xml
+++ b/cppguide.xml
@@ -4,7 +4,7 @@
Foo
in your source file, you
should bring in a definition for Foo
yourself,
@@ -383,11 +382,13 @@ Tashana Landray
.h
files.
- The preferred ordering reduces hidden dependencies. We want
- every header file to be compilable on its own. The easiest
- way to achieve this is to make sure that every one of them is
- the first .h
file #include
d in some
- .cc
.
+ With the preferred ordering, if dir/foo2.h
+ omits any necessary includes, the build of
+ dir/foo.cc
or
+ dir/foo_test.cc
will break.
+ Thus, this rule ensures that build breaks show up first
+ for the people working on these files, not for innocent people
+ in other packages.
Use namespaces according to the policy described below.
+ Terminate namespaces with comments as shown in the given examples.
dir/foo.cc
and
@@ -412,7 +413,6 @@ Tashana Landray
#include <sys/types.h>
#include <unistd.h>
-
#include <hash_map>
#include <vector>
@@ -468,6 +468,7 @@ Tashana Landray
//
- namespace
.
+ an unnamed namespace.
.h
@@ -1239,7 +1238,7 @@ Tashana Landray
An interface class can never be directly instantiated
because of the pure virtual method(s) it declares. To make
sure all implementations of the interface can be destroyed
- correctly, they must also declare a virtual destructor (in
+ correctly, the interface must also declare a virtual destructor (in
an exception to the first rule, this should not be pure). See
Stroustrup, The C++ Programming Language, 3rd
edition, section 12.4 for details.
@@ -1574,14 +1573,24 @@ Tashana Landray
non-const
reference parameters.
- One case when you might want an input parameter to be a
- const
pointer is if you want to emphasize that the
- argument is not copied, so it must exist for the lifetime of the
- object; it is usually best to document this in comments as
- well. STL adapters such as bind2nd
and
- mem_fun
do not permit reference parameters, so
- you must declare functions with pointer parameters in these
- cases, too.
+
+ However, there are some instances where using const T*
+ is preferable to const T&
for input parameters. For
+ example:
+
+ You want to pass in NULL.
+
+ The function saves a pointer or reference to the input.
+
+
+ Remember that most of the time input parameters are going to be
+ specified as const T&
. Using const T*
+ instead communicates to the reader that the input is somehow treated
+ differently. So if you choose const T*
rather than
+ const T&
, do so for a concrete reason; otherwise it
+ will likely confuse readers by making them look for an explanation
+ that doesn't exist.
+