storage/style.txt

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 Storage Module Style Guidelines
michael@0 2
michael@0 3 These guidelines should be followed for all new code in this module. Reviewers
michael@0 4 will be enforcing them, so please obey them!
michael@0 5
michael@0 6 * All code should be contained within the namespace mozilla::storage at a
michael@0 7 minimum. The use of namespaces is strongly encouraged.
michael@0 8
michael@0 9 * All functions being called in the global namespace should be prefixed with
michael@0 10 "::" to indicate that they are in the global namespace.
michael@0 11
michael@0 12 * The indentation level to use in source code is two spaces. No tabs, please!
michael@0 13
michael@0 14 * All files should have the following emacs and vim mode lines:
michael@0 15 -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
michael@0 16 vim: sw=2 ts=2 et lcs=trail\:.,tab\:>~ :
michael@0 17
michael@0 18 * All functions that are not XPCOM should start with a lowercase letter.
michael@0 19
michael@0 20 * Function arguments that are not out parameters should be prefixed with a (for
michael@0 21 pArameter), and use CamelCase.
michael@0 22
michael@0 23 * Function arguments that are out parameters should be prefixed with an
michael@0 24 underscore and have a descriptive name.
michael@0 25
michael@0 26 * Function declarations should include javadoc style comments.
michael@0 27
michael@0 28 * Javadoc @param tags should have the parameter description start on a new line
michael@0 29 aligned with the variable name. See the example below.
michael@0 30
michael@0 31 * Javadoc @return (note: non-plural) continuation lines should be lined up with
michael@0 32 the initial comment. See the example below.
michael@0 33
michael@0 34 * Javadoc @throws, like @param, should have the exception type on the same line
michael@0 35 as the @throws and the description on a new line indented to line up with
michael@0 36 the type of the exception.
michael@0 37
michael@0 38 * For function implementations, each argument should be on its own line.
michael@0 39
michael@0 40 * All variables should use camelCase.
michael@0 41
michael@0 42 * The use of bool is encouraged whenever the variable does not have the
michael@0 43 potential to go through xpconnect.
michael@0 44
michael@0 45 * For pointer variable types, include a space after the type before the asterisk
michael@0 46 and no space between the asterisk and variable name.
michael@0 47
michael@0 48 * If any part of an if-else block requires braces, all blocks need braces.
michael@0 49
michael@0 50 * Every else should be on a newline after a brace.
michael@0 51
michael@0 52 * Bracing should start on the line after a function and class definition. This
michael@0 53 goes for JavaScript code as well as C++ code.
michael@0 54
michael@0 55 * If a return value is not going to be checked, the return value should be
michael@0 56 explicitly casted to void (C style cast).
michael@0 57
michael@0 58
michael@0 59 BIG EXAMPLE:
michael@0 60
michael@0 61 *** Header ***
michael@0 62
michael@0 63 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
michael@0 64 * vim: sw=2 ts=2 et lcs=trail\:.,tab\:>~ : */
michael@0 65 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 66 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 67 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 68
michael@0 69 #ifndef mozilla_storage_FILENAME_h_
michael@0 70 #define mozilla_storage_FILENAME_h_
michael@0 71
michael@0 72 namespace mozilla {
michael@0 73 namespace storage {
michael@0 74
michael@0 75 class Foo : public Bar
michael@0 76 , public Baz
michael@0 77 {
michael@0 78 public:
michael@0 79 /**
michael@0 80 * Brief function summary.
michael@0 81 *
michael@0 82 * @param aArg1
michael@0 83 * Description description description description description etc etc
michael@0 84 * next line of description.
michael@0 85 * @param aArg2
michael@0 86 * Description description description.
michael@0 87 * @return Description description description description description etc etc
michael@0 88 * next line of description.
michael@0 89 *
michael@0 90 * @throws NS_ERROR_FAILURE
michael@0 91 * Okay, so this is for JavaScript code, but you probably get the
michael@0 92 * idea.
michael@0 93 */
michael@0 94 int chew(int aArg1, int aArg2);
michael@0 95 };
michael@0 96
michael@0 97 } // storage
michael@0 98 } // mozilla
michael@0 99
michael@0 100 #endif // mozilla_storage_FILENAME_h_
michael@0 101
michael@0 102
michael@0 103 *** Implementation ***
michael@0 104
michael@0 105 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
michael@0 106 * vim: sw=2 ts=2 et lcs=trail\:.,tab\:>~ : */
michael@0 107 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 108 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 109 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 110
michael@0 111 NS_IMPL_ISUPPORTS(
michael@0 112 Foo
michael@0 113 , IBar
michael@0 114 , IBaz
michael@0 115 )
michael@0 116
michael@0 117 Foo::Foo(
michael@0 118 LongArgumentLineThatWouldOtherwiseOverflow *aArgument1
michael@0 119 )
michael@0 120 : mField1(0)
michael@0 121 , mField2(0)
michael@0 122 {
michael@0 123 someMethodWithLotsOfParamsOrJustLongParameters(
michael@0 124 mLongFieldNameThatIsJustified,
michael@0 125 mMaybeThisOneIsLessJustifiedButBoyIsItLong,
michael@0 126 15
michael@0 127 );
michael@0 128 }
michael@0 129
michael@0 130 ////////////////////////////////////////////////////////////////////////////////
michael@0 131 //// Separate sections of the file like this
michael@0 132
michael@0 133 int
michael@0 134 Foo::chew(int aArg1, int aArg2)
michael@0 135 {
michael@0 136 (void)functionReturningAnIgnoredValue();
michael@0 137
michael@0 138 ::functionFromGlobalNamespaceWithVoidReturnValue();
michael@0 139
michael@0 140 return 0;
michael@0 141 }

mercurial