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 2024-07-24
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++14.
84 The code base assumes a POSIX.1-2008 compatible environment.
86 The required features are checked at build time, and it will either use
87 compatibility code in case the needed extensions are not supported and it
88 is possible to support them, otherwise it will abort in case a needed one
94 The coding style is a mix of parts from KNF [K] and the Linux CodingStyle [L].
95 If in doubt or missing from this file please ask, although files using the
96 tab based indentation can be considered canon.
98 [K] <https://www.freebsd.org/cgi/man.cgi?query=style>
99 [L] <https://kernel.org/doc/Documentation/process/coding-style.rst>
101 The code has a mix of an old coding style being phased out and the new
102 style. New files should use the new style, changes to files with the old
103 style should switch the code being touched except for the indentation level,
104 which should be preserved to match (2 spaces).
106 Code should generally strive for clarity. Monster functions should be split
107 into logical and small pieces.
109 Variable and function names should be generally descriptive, not needed
110 for variables commonly used (for example an index inside a loop, etc),
111 acronyms should only be used if they are widely known externally or
112 inside the project. The names should separate logical concepts within
115 On comments use UTF-8 characters for quotes, copyright symbols, etc.
117 On strings in code use simple or double quotes «''» «""». Not the unpaired
118 ones «`'». Strings marked for translation, should only be fixed if there's
119 other changes to be done on them, otherwise we get unneeded fuzzies.
121 <https://www.cl.cam.ac.uk/~mgk25/ucs/quotes.html>
126 Public declarations should be documented using JavaDoc style comments.
128 Documentation should always be close to its definition (usually in the .c
129 or .cc files) and not its declaration, so that when the code changes it's
130 less likely that they will get out of sync. For data types, macros and
131 similar where there's only declarations, the documentation will usually
132 go instead in the header files.
134 For enum values and struct members, the documentation should usually be
135 one-line comments, preceding the item.
137 The comment title should be on the second line on its own, and the long
138 description on its own paragraph.
143 * This is the enum title.
146 /** Value doing foo. */
148 /** Value doing bar. */
155 * This is the long description extending several lines, explaining in
156 * detail what this item does.
158 * @param a This is the a parameter.
159 * @param b This is the b parameter.
161 * @return This is the return value.
164 Indentation, alignment and spacing
165 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
167 Lines should be 80 chars max. Indentation is done with hard tabs (which
168 should be considered to take 8 spaces width). Aligning with spaces:
171 function(void *ptr, int value)
173 void *ref_ptr = get_ref(ptr);
174 int ref_value = get_value(ref);
177 do_something(GLOBAL_MACRO, ptr, value, "some-string",
178 ref_ptr, ref_value, "other-string",
182 When wrapping, logical operators should be kept on the preceding line:
184 if (really_long_variable_to_be_checked_against_a &&
185 really_long_variable_to_be_checked_against_b)
188 Spaces around operators:
190 if (a && (b || c) && c == d)
193 a = (b + 4 * (5 - 6)) & 0xff;
195 Spaces around assignments:
203 Space after keywords (for, while, do, if, etc, but sizeof should be
204 treated like a function):
206 for (i = 0; i < 10; i++)
209 memcpy(dst, src, sizeof(src));
211 Definition of local variables, related code blocks, functions bodies
212 should be split with blank lines:
230 Braces should be placed on the same line as the keyword, but on a new line
231 for the function body. No braces should be used for unambiguous one line
265 Prefer assigning outside of conditionals:
271 String comparisons should use comparison operators to make it easier to
272 see what operation is being done:
274 if (strcmp(a, b) == 0)
277 if (strcmp(a, b) < 0)
281 Dpkg Perl coding style 2019-03-27
282 ======================
287 We don't want to impose a too-recent Perl version, so only use features
288 supported by the Perl version that is currently in Debian oldstable when
289 possible. Currently that means Perl 5.32.1.
294 In general you should follow the conventions listed in perlstyle(1).
295 All the code should run with the “use strict” and “use warnings” pragmas,
296 and pass «make authorcheck».
301 Public modules should be documented with POD (see perlpod(1)). Private
302 code doesn't have to use POD, simple comment lines (starting with "#") are
303 enough, but if they use POD they need to note the fact that the module is
304 private in the CHANGES section and specify a version «0.xx». Public scripts
305 are documented in their corresponding manual pages.
307 Indentation, alignment and spacing
308 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
310 Lines should be 80 chars max. The indentation level is 4 characters, and
311 indentation is done with soft tabs (no hard tabs) and spaces.
317 print "Who are you?\n";
325 Use a single line to retrieve all the arguments and use $self as name
326 for the current object:
329 my ($self, $arg1, $arg2, %opts) = @_;
333 Supplementary optional arguments should be named and thus stored in a