1 Dpkg POD coding style 2021-06-25
7 Verbatim code sections that need to be formatted, need to be prefixed with
8 a line containing exactly «Z<>», to trick the parser.
10 New sentences inside a paragraph should start on a new line, so that we
11 do not need to reflow the text when adding new content.
13 Every new feature, option or behavior change needs to be documented with
14 the version introducing the change.
17 Dpkg M4sh/Autoconf coding style 2016-09-05
18 ===============================
23 All dpkg specific macros need to be prefixed with «DPKG_». Complex checks
24 should be defined as new macros under m4/dpkg-<name>.m4, and those used
25 in configure.ac which should look pretty simple.
27 Quoting and indentation
28 ~~~~~~~~~~~~~~~~~~~~~~~
30 Code and arguments that wrap into the next line are indented by two spaces.
32 In principle all macro argument should always be quoted. Which brings one
33 of the biggest readability issues with M4sh/Autoconf code, the amount of
34 consecutive quotes and parenthesis pairs, which can make it very hard to
35 notice if they are unbalanced. To avoid this we use a style that tries to
36 avoid more than two consecutive blocks of «])».
38 We can either use a style resembling very simple function calls, when the
39 arguments are as well very simple, such as:
41 AC_DEFINE_UNQUOTED([SOME_VARIABLE],
42 [SOME_CONCOCTED_WAY_TO_GET_A_VALUE],
43 [Some descriptive text here])
49 Or one resembling curly-braced C-style blocks, such as this:
57 Except for AC_ARG_WITH, AC_ARG_ENABLE and AM_CONDITIONAL which need their
58 second argument quoted tightly surrounding the code, like this:
60 AC_ARG_ENABLE([feature],
61 [AS_HELP_STRING([--disable-feature], [Disable feature])],
62 [], [enable_feature="yes"])
64 AM_CONDITIONAL([HAVE_SOME_FEATURE],
65 [test "x$ac_cv_have_some_feature" = "xyes" && \
66 test "x$ac_cv_have_some_feature" = "xyes"])
68 or the output will get messed up.
71 Dpkg C/C++ coding style 2016-01-29
72 =======================
77 The C code base assumes C99, except for the following features:
79 - Variable length arrays.
80 - Mixed declaration and code.
82 The C++ code base assumes C++03, plus the following C++11 extension:
84 + Null pointer keyword (nullptr).
86 The code base assumes a POSIX.1-2008 compatible environment.
88 The required features are checked at build time, and it will either use
89 compatibility code in case the needed extensions are not supported and it
90 is possible to support them, otherwise it will abort in case a needed one
96 The coding style is a mix of parts from KNF [K] and the Linux CodingStyle [L].
97 If in doubt or missing from this file please ask, although files using the
98 tab based indentation can be considered canon.
100 [K] <https://www.freebsd.org/cgi/man.cgi?query=style>
101 [L] <https://www.kernel.org/doc/Documentation/CodingStyle>
103 The code has a mix of an old coding style being phased out and the new
104 style. New files should use the new style, changes to files with the old
105 style should switch the code being touched except for the indentation level,
106 which should be preserved to match (2 spaces).
108 Code should generally strive for clarity. Monster functions should be split
109 into logical and small pieces.
111 Variable and function names should be generally descriptive, not needed
112 for variables commonly used (for example an index inside a loop, etc),
113 acronyms should only be used if they are widely known externally or
114 inside the project. The names should separate logical concepts within
117 On comments use UTF-8 characters for quotes, copyright symbols, etc.
119 On strings in code use simple or double quotes «''» «""». Not the unpaired
120 ones «`'». Strings marked for translation, should only be fixed if there's
121 other changes to be done on them, otherwise we get unneeded fuzzies.
123 <https://www.cl.cam.ac.uk/~mgk25/ucs/quotes.html>
128 Public declarations should be documented using JavaDoc style comments.
130 Documentation should always be close to its definition (usually in the .c
131 or .cc files) and not its declaration, so that when the code changes it's
132 less likely that they will get out of sync. For data types, macros and
133 similar where there's only declarations, the documentation will usually
134 go instead in the header files.
136 For enum values and struct members, the documentation should usually be
137 one-line comments, preceding the item.
139 The comment title should be on the second line on its own, and the long
140 description on its own paragraph.
145 * This is the enum title.
148 /** Value doing foo. */
150 /** Value doing bar. */
157 * This is the long description extending several lines, explaining in
158 * detail what this item does.
160 * @param a This is the a parameter.
161 * @param b This is the b parameter.
163 * @return This is the return value.
166 Indentation, alignment and spacing
167 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
169 Lines should be 80 chars max. Indentation is done with hard tabs (which
170 should be considered to take 8 spaces width). Aligning with spaces:
173 function(void *ptr, int value)
175 void *ref_ptr = get_ref(ptr);
176 int ref_value = get_value(ref);
179 do_something(GLOBAL_MACRO, ptr, value, "some-string",
180 ref_ptr, ref_value, "other-string",
184 When wrapping, logical operators should be kept on the preceding line:
186 if (really_long_variable_to_be_checked_against_a &&
187 really_long_variable_to_be_checked_against_b)
190 Spaces around operators:
192 if (a && (b || c) && c == d)
195 a = (b + 4 * (5 - 6)) & 0xff;
197 Spaces around assignments:
205 Space after keywords (for, while, do, if, etc, but sizeof should be
206 treated like a function):
208 for (i = 0; i < 10; i++)
211 memcpy(dst, src, sizeof(src));
213 Definition of local variables, related code blocks, functions bodies
214 should be split with blank lines:
232 Braces should be placed on the same line as the keyword, but on a new line
233 for the function body. No braces should be used for unambiguous one line
267 Prefer assigning outside of conditionals:
273 String comparisons should use comparison operators to make it easier to
274 see what operation is being done:
276 if (strcmp(a, b) == 0)
279 if (strcmp(a, b) < 0)
283 Dpkg Perl coding style 2019-03-27
284 ======================
289 We don't want to impose a too-recent Perl version, so only use features
290 supported by the Perl version that is currently in Debian oldstable when
291 possible. Currently that means Perl 5.32.1.
296 In general you should follow the conventions listed in perlstyle(1).
297 All the code should run with the “use strict” and “use warnings” pragmas,
298 and pass «make authorcheck».
303 Public modules should be documented with POD (see perlpod(1)). Private
304 code doesn't have to use POD, simple comment lines (starting with "#") are
305 enough, but if they use POD they need to note the fact that the module is
306 private in the CHANGES section and specify a version «0.xx». Public scripts
307 are documented in their corresponding manual pages.
309 Indentation, alignment and spacing
310 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
312 Lines should be 80 chars max. The indentation level is 4 characters, and
313 indentation is done with soft tabs (no hard tabs) and spaces.
319 print "Who are you?\n";
327 Use a single line to retrieve all the arguments and use $self as name
328 for the current object:
331 my ($self, $arg1, $arg2, %opts) = @_;
335 Supplementary optional arguments should be named and thus stored in a