aboutsummaryrefslogtreecommitdiffstats
path: root/Documentation/CodingStyle
diff options
context:
space:
mode:
authorMauro Carvalho Chehab <mchehab@s-opensource.com>2016-09-19 07:07:45 -0400
committerJonathan Corbet <corbet@lwn.net>2016-09-20 20:36:53 -0400
commitb1a3459b00d601149d9171c0075ee35ea2d3bfde (patch)
tree434723e6654e479f03ae025fdd74557c1afc8bb0 /Documentation/CodingStyle
parentd8dbbbc54f0e4f70453019d236028c36a482aee9 (diff)
Documentation/CodingStyle: use the proper tag for verbatim font
On Sphinx/ReST notation, ``foo`` means that foo will be will be marked as inline literal, effectively making it to be presented as a monospaced font. As we want this document to be parsed by Sphinx, instead of using "foo", use ``foo`` for the names that are literal, because it is an usual typographic convention to use monospaced fonts for functions and language commands on documents, and we're following such convention on the other ReST books. Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com> Signed-off-by: Jonathan Corbet <corbet@lwn.net>
Diffstat (limited to 'Documentation/CodingStyle')
-rw-r--r--Documentation/CodingStyle98
1 files changed, 49 insertions, 49 deletions
diff --git a/Documentation/CodingStyle b/Documentation/CodingStyle
index f103de7e2028..c25528d76af1 100644
--- a/Documentation/CodingStyle
+++ b/Documentation/CodingStyle
@@ -37,8 +37,8 @@ benefit of warning you when you're nesting your functions too deep.
37Heed that warning. 37Heed that warning.
38 38
39The preferred way to ease multiple indentation levels in a switch statement is 39The preferred way to ease multiple indentation levels in a switch statement is
40to align the "switch" and its subordinate "case" labels in the same column 40to align the ``switch`` and its subordinate ``case`` labels in the same column
41instead of "double-indenting" the "case" labels. E.g.: 41instead of ``double-indenting`` the ``case`` labels. E.g.:
42 42
43.. code-block:: c 43.. code-block:: c
44 44
@@ -141,7 +141,7 @@ special anyway (you can't nest them in C).
141 141
142Note that the closing brace is empty on a line of its own, _except_ in 142Note that the closing brace is empty on a line of its own, _except_ in
143the cases where it is followed by a continuation of the same statement, 143the cases where it is followed by a continuation of the same statement,
144ie a "while" in a do-statement or an "else" in an if-statement, like 144ie a ``while`` in a do-statement or an ``else`` in an if-statement, like
145this: 145this:
146 146
147.. code-block:: c 147.. code-block:: c
@@ -228,7 +228,7 @@ Do not add spaces around (inside) parenthesized expressions. This example is
228 s = sizeof( struct file ); 228 s = sizeof( struct file );
229 229
230When declaring pointer data or a function that returns a pointer type, the 230When declaring pointer data or a function that returns a pointer type, the
231preferred use of '\*' is adjacent to the data name or function name and not 231preferred use of ``*`` is adjacent to the data name or function name and not
232adjacent to the type name. Examples: 232adjacent to the type name. Examples:
233 233
234.. code-block:: c 234.. code-block:: c
@@ -255,10 +255,10 @@ no space after the prefix increment & decrement unary operators::
255 255
256 ++ -- 256 ++ --
257 257
258and no space around the '.' and "->" structure member operators. 258and no space around the ``.`` and ``->`` structure member operators.
259 259
260Do not leave trailing whitespace at the ends of lines. Some editors with 260Do not leave trailing whitespace at the ends of lines. Some editors with
261"smart" indentation will insert whitespace at the beginning of new lines as 261``smart`` indentation will insert whitespace at the beginning of new lines as
262appropriate, so you can start typing the next line of code right away. 262appropriate, so you can start typing the next line of code right away.
263However, some such editors do not remove the whitespace if you end up not 263However, some such editors do not remove the whitespace if you end up not
264putting a line of code there, such as if you leave a blank line. As a result, 264putting a line of code there, such as if you leave a blank line. As a result,
@@ -276,17 +276,17 @@ context lines.
276C is a Spartan language, and so should your naming be. Unlike Modula-2 276C is a Spartan language, and so should your naming be. Unlike Modula-2
277and Pascal programmers, C programmers do not use cute names like 277and Pascal programmers, C programmers do not use cute names like
278ThisVariableIsATemporaryCounter. A C programmer would call that 278ThisVariableIsATemporaryCounter. A C programmer would call that
279variable "tmp", which is much easier to write, and not the least more 279variable ``tmp``, which is much easier to write, and not the least more
280difficult to understand. 280difficult to understand.
281 281
282HOWEVER, while mixed-case names are frowned upon, descriptive names for 282HOWEVER, while mixed-case names are frowned upon, descriptive names for
283global variables are a must. To call a global function "foo" is a 283global variables are a must. To call a global function ``foo`` is a
284shooting offense. 284shooting offense.
285 285
286GLOBAL variables (to be used only if you _really_ need them) need to 286GLOBAL variables (to be used only if you _really_ need them) need to
287have descriptive names, as do global functions. If you have a function 287have descriptive names, as do global functions. If you have a function
288that counts the number of active users, you should call that 288that counts the number of active users, you should call that
289"count_active_users()" or similar, you should _not_ call it "cntusr()". 289``count_active_users()`` or similar, you should _not_ call it ``cntusr()``.
290 290
291Encoding the type of a function into the name (so-called Hungarian 291Encoding the type of a function into the name (so-called Hungarian
292notation) is brain damaged - the compiler knows the types anyway and can 292notation) is brain damaged - the compiler knows the types anyway and can
@@ -294,9 +294,9 @@ check those, and it only confuses the programmer. No wonder MicroSoft
294makes buggy programs. 294makes buggy programs.
295 295
296LOCAL variable names should be short, and to the point. If you have 296LOCAL variable names should be short, and to the point. If you have
297some random integer loop counter, it should probably be called "i". 297some random integer loop counter, it should probably be called ``i``.
298Calling it "loop_counter" is non-productive, if there is no chance of it 298Calling it ``loop_counter`` is non-productive, if there is no chance of it
299being mis-understood. Similarly, "tmp" can be just about any type of 299being mis-understood. Similarly, ``tmp`` can be just about any type of
300variable that is used to hold a temporary value. 300variable that is used to hold a temporary value.
301 301
302If you are afraid to mix up your local variable names, you have another 302If you are afraid to mix up your local variable names, you have another
@@ -307,7 +307,7 @@ See chapter 6 (Functions).
3075) Typedefs 3075) Typedefs
308----------- 308-----------
309 309
310Please don't use things like "vps_t". 310Please don't use things like ``vps_t``.
311It's a _mistake_ to use typedef for structures and pointers. When you see a 311It's a _mistake_ to use typedef for structures and pointers. When you see a
312 312
313.. code-block:: c 313.. code-block:: c
@@ -322,35 +322,35 @@ In contrast, if it says
322 322
323 struct virtual_container *a; 323 struct virtual_container *a;
324 324
325you can actually tell what "a" is. 325you can actually tell what ``a`` is.
326 326
327Lots of people think that typedefs "help readability". Not so. They are 327Lots of people think that typedefs ``help readability``. Not so. They are
328useful only for: 328useful only for:
329 329
330 (a) totally opaque objects (where the typedef is actively used to _hide_ 330 (a) totally opaque objects (where the typedef is actively used to _hide_
331 what the object is). 331 what the object is).
332 332
333 Example: "pte_t" etc. opaque objects that you can only access using 333 Example: ``pte_t`` etc. opaque objects that you can only access using
334 the proper accessor functions. 334 the proper accessor functions.
335 335
336 NOTE! Opaqueness and "accessor functions" are not good in themselves. 336 NOTE! Opaqueness and ``accessor functions`` are not good in themselves.
337 The reason we have them for things like pte_t etc. is that there 337 The reason we have them for things like pte_t etc. is that there
338 really is absolutely _zero_ portably accessible information there. 338 really is absolutely _zero_ portably accessible information there.
339 339
340 (b) Clear integer types, where the abstraction _helps_ avoid confusion 340 (b) Clear integer types, where the abstraction _helps_ avoid confusion
341 whether it is "int" or "long". 341 whether it is ``int`` or ``long``.
342 342
343 u8/u16/u32 are perfectly fine typedefs, although they fit into 343 u8/u16/u32 are perfectly fine typedefs, although they fit into
344 category (d) better than here. 344 category (d) better than here.
345 345
346 NOTE! Again - there needs to be a _reason_ for this. If something is 346 NOTE! Again - there needs to be a _reason_ for this. If something is
347 "unsigned long", then there's no reason to do 347 ``unsigned long``, then there's no reason to do
348 348
349 typedef unsigned long myflags_t; 349 typedef unsigned long myflags_t;
350 350
351 but if there is a clear reason for why it under certain circumstances 351 but if there is a clear reason for why it under certain circumstances
352 might be an "unsigned int" and under other configurations might be 352 might be an ``unsigned int`` and under other configurations might be
353 "unsigned long", then by all means go ahead and use a typedef. 353 ``unsigned long``, then by all means go ahead and use a typedef.
354 354
355 (c) when you use sparse to literally create a _new_ type for 355 (c) when you use sparse to literally create a _new_ type for
356 type-checking. 356 type-checking.
@@ -359,10 +359,10 @@ useful only for:
359 exceptional circumstances. 359 exceptional circumstances.
360 360
361 Although it would only take a short amount of time for the eyes and 361 Although it would only take a short amount of time for the eyes and
362 brain to become accustomed to the standard types like 'uint32_t', 362 brain to become accustomed to the standard types like ``uint32_t``,
363 some people object to their use anyway. 363 some people object to their use anyway.
364 364
365 Therefore, the Linux-specific 'u8/u16/u32/u64' types and their 365 Therefore, the Linux-specific ``u8/u16/u32/u64`` types and their
366 signed equivalents which are identical to standard types are 366 signed equivalents which are identical to standard types are
367 permitted -- although they are not mandatory in new code of your 367 permitted -- although they are not mandatory in new code of your
368 own. 368 own.
@@ -373,7 +373,7 @@ useful only for:
373 (e) Types safe for use in userspace. 373 (e) Types safe for use in userspace.
374 374
375 In certain structures which are visible to userspace, we cannot 375 In certain structures which are visible to userspace, we cannot
376 require C99 types and cannot use the 'u32' form above. Thus, we 376 require C99 types and cannot use the ``u32`` form above. Thus, we
377 use __u32 and similar types in all structures which are shared 377 use __u32 and similar types in all structures which are shared
378 with userspace. 378 with userspace.
379 379
@@ -440,13 +440,13 @@ locations and some common work such as cleanup has to be done. If there is no
440cleanup needed then just return directly. 440cleanup needed then just return directly.
441 44