The Fuchsia project follows the Google C++ style guide, with a few exceptions.
By policy, code should be formatted by clang-format which should handle many decisions.
Always use braces { }
when the contents of a block are more than one line. This is something you need to watch since Clang-format doesn't know to add these.
// Don't do this. while (!done) doSomethingWithAReallyLongLine( wrapped_arg); // Correct. while (!done) { doSomethingWithAReallyLongLine( wrapped_arg); }
Do not use spaces inside parentheses (the Google style guide discourages but permits this).
Do not use the single-line form for short conditionals and loops (the Google style guide permits both forms):
// Don't do this: if (x == kFoo) return new Foo(); // Correct. if (x == kFoo) return new Foo;
internal
(when required to hide implementation details of templated code)internal
fuchsia
(except in code generated by the FIDL compiler)media
) are best avoided.Rationale: Tip of the Week #130: Namespace Naming
#include
s#include
s use either <angle brackets>
or "quotes"
depending on context.
""
if the path is from the root of the source tree (e.g. "garnet/foo/bar/baz.h"
) or if the include is in the same directory as the includer (e.g. "baz.h"
).<>
otherwise, which typically means the header is a “public” header of some sort (e.g. <lib/foo/bar.h>
or <zircon/foo.h>
)."third_party/skia/include/core/SkPaint.h"
) or a public include path (e.g. <gtest/gtest.h>
).<>
with their canonical path (e.g. <lib/foo/bar.h>
) even if included from the same directory."garnet/foo/bar/baz.h"
) even if included from the same directory, except in cases where this would be inconsistent with existing code (e.g. zircon).