Update Style Guide documentation to explain basic type rules.
[openocd.git] / doc / manual / style.txt
1 /** @page styleguide Style Guides
2
3 The goals for each of these guides are:
4 - to produce correct code that appears clean, consistent, and readable,
5 - to allow developers to create patches that conform to a standard, and
6 - to eliminate these issues as points of future contention.
7
8 Some of these rules may be ignored in the spirit of these stated goals;
9 however, such exceptions should be fairly rare.
10
11 The following style guides describe a formatting, naming, and other
12 conventions that should be followed when writing or changing the OpenOCD
13 code:
14
15 - @subpage styletcl
16 - @subpage stylec
17 - @subpage styleperl
18 - @subpage styleautotools
19
20 In addition, the following style guides provide information for
21 providing documentation, either as part of the C code or stand-alone.
22
23 - @subpage styledoxygen
24 - @subpage styletexinfo
25 - @subpage stylelatex
26
27 Feedback would be welcome to improve the OpenOCD guidelines.
28
29 */
30 /** @page styletcl TCL Style Guide
31
32 OpenOCD needs to expand its Jim/TCL Style Guide.
33
34 Many of the guidelines listed on the @ref stylec page should apply to
35 OpenOCD's Jim/TCL code as well.
36
37 */
38 /** @page stylec C Style Guide
39
40 This page contains guidelines for writing new C source code for the
41 OpenOCD project.
42
43 @section styleformat Formatting Guide
44
45 - remove any trailing white space at the end of lines.
46 - use TAB characters for indentation; do NOT use spaces.
47 - displayed TAB width is 4 characters.
48 - use Unix line endings ('\\n'); do NOT use DOS endings ('\\r\\n')
49 - limit adjacent empty lines to at most two (2).
50 - remove any trailing empty lines at the end of source files
51 - do not "comment out" code from the tree; instead, one should either:
52 -# remove it entirely (Subversion can retrieve the old version), or
53 -# use an @c \#if/\#endif block.
54
55 Finally, try to avoid lines of code that are longer than than 72-80 columns:
56
57 - long lines frequently indicate other style problems:
58 - insufficient use of static functions, macros, or temporary variables
59 - poor flow-control structure; "inverted" logical tests
60 - a few lines may be wider than this limit (typically format strings), but:
61 - all C compilers will concatenate series of string constants.
62 - all long string constants should be split across multiple lines.
63
64 @section stylenames Naming Rules
65
66 - most identifiers must use lower-case letters (and digits) only.
67 - macros must use upper-case letters (and digits) only.
68 - OpenOCD identifiers should NEVER use @c MixedCaps.
69 - structure names must end with the '_s' suffix.
70 - typedef names must end with the '_t' suffix.
71 - use underline characters between consecutive words in identifiers
72 (e.g. @c more_than_one_word).
73
74 @section stylec99 C99 Rules
75
76 - inline functions
77 - @c // comments -- in new code, prefer these for single-line comments
78 - trailing comma allowed in enum declarations
79 - designated initializers (@{ .field = value @})
80 - variables declarations may be mixed with code
81 - new block scopes for selection and iteration statements
82
83 @section styletypes Type Guidelines
84 - use native types (@c int or @c unsigned) if the type is not important
85 - if size matters, use the types from \<stdint.h\> or \<inttypes.h\>:
86 - @c int8_t, @c int16_t, @c int32_t, or @c int64_t: signed types of specified size
87 - @c uint8_t, @c uint16_t, @c uint32_t, or @c uint64_t: unsigned types of specified size
88 - do @b NOT redefine @c uN types from "types.h"
89
90 @section stylefunc Functions
91
92 - static inline functions should be prefered over macros:
93 @code
94 /** do NOT define macro-like functions like this... */
95 #define CUBE(x) ((x) * (x) * (x))
96 /** instead, define the same expression using a C99 inline function */
97 static inline int cube(int x) { return x * x * x; }
98 @endcode
99 - Functions should be declared static unless required by other modules
100 - define static functions before first usage to avoid forward declarations.
101 - Functions should have no space between its name and its parameter list:
102 @code
103 int f(int x1, int x2)
104 {
105 ...
106 int y = f(x1, x2 - x1);
107 ...
108 }
109 @endcode
110
111 */
112 /** @page styledoxygen Doxygen Style Guide
113
114 The following sections provide guidelines for OpenOCD developers
115 who wish to write Doxygen comments in the code or this manual.
116 For an introduction to Doxygen documentation,
117 see the @ref primerdoxygen.
118
119 @section styledoxyblocks Doxygen Block Selection
120
121 Several different types of Doxygen comments can be used; often,
122 one style will be the most appropriate for a specific context.
123 The following guidelines provide developers with heuristics for
124 selecting an appropriate form and writing consistent documentation
125 comments.
126
127 -# use @c /// to for one-line documentation of instances.
128 -# for documentation requiring multiple lines, use a "block" style:
129 @verbatim
130 /**
131 * @brief First sentence is short description. Remaining text becomes
132 * the full description block, where "empty" lines start new paragraphs.
133 *
134 * One can make text appear in @a italics, @b bold, @c monospace, or
135 * in blocks such as the one in which this example appears in the Style
136 * Guide. See the Doxygen Manual for the full list of commands.
137 *
138 * @param foo For a function, describe the parameters (e.g. @a foo).
139 * @returns The value(s) returned, or possible error conditions.
140 */
141 @endverbatim
142 -# The block should start on the line following the opening @c /**.
143 -# The end of the block, \f$*/\f$, should also be on its own line.
144 -# Every line in the block should have a @c '*' in-line with its start:
145 - A leading space is required to align the @c '*' with the @c /** line.
146 - A single "empty" line should separate the function documentation
147 from the block of parameter and return value descriptions.
148 - Except to separate paragraphs of documentation, other extra
149 "empty" lines should be removed from the block.
150 -# Only single spaces should be used; do @b not add mid-line indentation.
151 -# If the total line length will be less than 72-80 columns, then
152 - The @c /**< form can be used on the same line.
153 - This style should be used sparingly; the best use is for fields:
154 @code int field; /**< field description */ @endcode
155
156 @section styledoxyall Doxygen Style Guide
157
158 The following guidelines apply to all Doxygen comment blocks:
159
160 -# Use the @c '\@cmd' form for all doxygen commands (do @b not use @c '\\cmd').
161 -# Use symbol names such that Doxygen automatically creates links:
162 -# @c function_name() can be used to reference functions
163 (e.g. flash_set_dirty()).
164 -# @c struct_name::member_name should be used to reference structure
165 fields in the documentation (e.g. @c flash_driver_s::name).
166 -# URLS get converted to markup automatically, without any extra effort.
167 -# new pages can be linked into the heirarchy by using the @c \@subpage
168 command somewhere the page(s) under which they should be linked:
169 -# use @c \@ref in other contexts to create links to pages and sections.
170 -# Use good Doxygen mark-up:
171 -# '\@a' (italics) should be used to reference parameters (e.g. <i>foo</i>).
172 -# '\@b' (bold) should be used to emphasizing <b>single</b> words.
173 -# '\@c' (monospace) should be used with <code>file names</code> and
174 <code>code symbols</code>, so they appear visually distinct from
175 surrounding text.
176 -# To mark-up multiple words, the HTML alternatives must be used.
177 -# Two spaces should be used when nesting lists; do @b not use '\\t' in lists.
178 -# Code examples provided in documentation must conform to the Style Guide.
179
180 @section styledoxytext Doxygen Text Inputs
181
182 In addition to the guidelines in the preceding sections, the following
183 additional style guidelines should be considered when writing
184 documentation as part of standalone text files:
185
186 -# Text files must contain Doxygen at least one comment block:
187 -# Documentation should begin in the first column (except for nested lists).
188 -# Do NOT use the @c '*' convention that must be used in the source code.
189 -# Each file should contain at least one @c \@page block.
190 -# Each new page should be listed as a \@subpage in the \@page block
191 of the page that should serve as its parent.
192 -# Large pages should be structure in parts using meaningful \@section
193 and \@subsection commands.
194 -# Include a @c \@file block at the end of each Doxygen @c .txt file to
195 document its contents:
196 - Doxygen creates such pages for files automatically, but no content
197 will appear on them for those that only contain manual pages.
198 - The \@file block should provide useful meta-documentation to assist
199 techincal writers; typically, a list of the pages that it contains.
200 - For example, the @ref styleguide exists in @c doc/manual/style.txt,
201 which contains a reference back to itself.
202 -# The \@file and \@page commands should begin on the same line as
203 the start of the Doxygen comment:
204 @verbatim
205 /** @page pagename Page Title
206
207 Documentation for the page.
208
209 */
210 /** @file
211
212 This file contains the @ref pagename page.
213
214 */
215 @endverbatim
216
217 For an example, the Doxygen source for this Style Guide can be found in
218 @c doc/manual/style.txt, alongside other parts of The Manual.
219
220 */
221 /** @page styletexinfo Texinfo Style Guide
222
223 The User's Guide is there to provide two basic kinds of information. It
224 is a guide for how and why to use each feature or mechanism of OpenOCD.
225 It is also the reference manual for all commands and options involved
226 in using them, including interface, flash, target, and other drivers.
227 At this time, it is the only user-targetted documentation; everything
228 else is addressing OpenOCD developers.
229
230 There are two key audiences for the User's Guide, both developer based.
231 The primary audience is developers using OpenOCD as a tool in their
232 work, or who may be starting to use it that way. A secondary audience
233 includes developers who are supporting those users by packaging or
234 customizing it for their hardware, installing it as part of some software
235 distribution, or by evolving OpenOCD itself. There is some crossover
236 between those audiences. We encourage contributions from users as the
237 fundamental way to evolve and improve OpenOCD. In particular, creating
238 a board or target specific configuration file is something that many
239 users will end up doing at some point, and we like to see such files
240 become part of the mainline release.
241
242 General documentation rules to remember include:
243
244 - Be concise and clear. It's work to remove those extra words and
245 sentences, but such "noise" doesn't help readers.
246 - Make it easy to skim and browse. "Tell what you're going to say,
247 then say it". Help readers decide whether to dig in now, or
248 leave it for later.
249 - Make sure the chapters flow well. Presentations should not jump
250 around, and should move easily from overview down to details.
251 - Avoid using the passive voice.
252 - Address the reader to clarify roles ("your config file", "the board you
253 are debugging", etc.); "the user" (etc) is artificial.
254 - Use good English grammar and spelling. Remember also that English
255 will not be the first language for many readers. Avoid complex or
256 idiomatic usage that could create needless barriers.
257 - Use examples to highlight fundamental ideas and common idioms.
258 - Don't overuse list constructs. This is not a slide presentation;
259 prefer paragraphs.
260
261 When presenting features and mechanisms of OpenOCD:
262
263 - Explain key concepts before presenting commands using them.
264 - Tie examples to common developer tasks.
265 - When giving instructions, you can \@enumerate each step both
266 to clearly delineate the steps, and to highlight that this is
267 not explanatory text.
268 - When you provide "how to use it" advice or tutorials, keep it
269 in separate sections from the reference material.
270 - Good indexing is something of a black art. Use \@cindex for important
271 concepts, but don't overuse it. In particular, rely on the \@deffn
272 indexing, and use \@cindex primarily with significant blocks of text
273 such as \@subsection. The \@dfn of a key term may merit indexing.
274 - Use \@xref (and \@anchor) with care. Hardcopy versions, from the PDF,
275 must make sense without clickable links (which don't work all that well
276 with Texinfo in any case). If you find you're using many links,
277 read that as a symptom that the presentation may be disjointed and
278 confusing.
279 - Avoid font tricks like \@b, but use \@option, \@file, \@dfn, \@emph
280 and related mechanisms where appropriate.
281
282 For technical reference material:
283
284 - It's OK to start sections with explanations and end them with
285 detailed lists of the relevant commands.
286 - Use the \@deffn style declarations to define all commands and drivers.
287 These will automatically appear in the relevant index, and those
288 declarations help promote consistent presentation and style.
289 - It's a "Command" if it can be used interactively.
290 - Else it's a "Config Command" if it must be used before the
291 configuration stage completes.
292 - For a "Driver", list its name.
293 - Use BNF style regular expressions to define parameters:
294 brackets around zero-or-one choices, parentheses around
295 exactly-one choices.
296 - Use \@option, \@file, \@var and other mechanisms where appropriate.
297 - Say what output it displays, and what value it returns to callers.
298 - Explain clearly what the command does. Sometimes you will find
299 that it can't be explained clearly. That usually means the command
300 is poorly designed; replace it with something better, if you can.
301 - Be complete: document all commands, except as part of a strategy
302 to phase something in or out.
303 - Be correct: review the documentation against the code, and
304 vice versa.
305 - Alphabetize the \@defn declarations for all commands in each
306 section.
307 - Keep the per-command documentation focussed on exactly what that
308 command does, not motivation, advice, suggestions, or big examples.
309 When commands deserve such expanded text, it belongs elsewhere.
310 Solutions might be using a \@section explaining a cluster of related
311 commands, or acting as a mini-tutorial.
312 - Details for any given driver should be grouped together.
313
314 The User's Guide is the first place most users will start reading,
315 after they begin using OpenOCD. Make that investment of their time
316 be as productive as possible. Needing to look at OpenOCD source code,
317 to figure out how to use it is a bad sign, though it's OK to need to
318 look at the User's guide to figure out what a config script is doing.
319
320 */
321 /** @page stylelatex LaTeX Style Guide
322
323 This page needs to provide style guidelines for using LaTeX, the
324 typesetting language used by The References for OpenOCD Hardware.
325 Likewise, the @ref primerlatex for using this guide needs to be completed.
326
327 */
328 /** @page styleperl Perl Style Guide
329
330 This page provides some style guidelines for using Perl, a scripting
331 language used by several small tools in the tree:
332
333 -# Ensure all Perl scripts use the proper suffix (@c .pl for scripts, and
334 @c .pm for modules)
335 -# Pass files as script parameters or piped as input:
336 - Do NOT code paths to files in the tree, as this breaks out-of-tree builds.
337 - If you must, then you must also use an automake rule to create the script.
338 -# use @c '#!/usr/bin/perl' as the first line of Perl scripts.
339 -# always <code>use strict</code> and <code>use warnings</code>
340 -# invoke scripts indirectly in Makefiles or other scripts:
341 @code
342 perl script.pl
343 @endcode
344
345 Maintainers must also be sure to follow additional guidelines:
346 -# Ensure that Perl scripts are committed as executables:
347 - Use "<code>chmod +x script.pl</code>"
348 @a before using "<code>svn add script.pl</code>", or
349 - Use "<code>svn ps svn:executable '*' script.pl</code>"
350 @a after using "<code>svn add script.pl</code>".
351
352 */
353 /** @page styleautotools Autotools Style Guide
354
355 This page contains style guidelines for the OpenOCD autotools scripts.
356
357 The following guidelines apply to the @c configure.in file:
358 - Better guidelines need to be developed, but until then...
359 - Use good judgement.
360
361 The following guidelines apply to @c Makefile.am files:
362 -# When assigning variables with long lists of items:
363 -# Separate the values on each line to make the files "patch friendly":
364 @code
365 VAR = \
366 value1 \
367 value2 \
368 ...
369 value9 \
370 value10
371 @endcode
372 */
373 /** @file
374
375 This file contains the @ref styleguide pages. The @ref styleguide pages
376 include the following Style Guides for their respective code and
377 documentation languages:
378
379 - @ref styletcl
380 - @ref stylec
381 - @ref styledoxygen
382 - @ref styletexinfo
383 - @ref stylelatex
384 - @ref styleperl
385 - @ref styleautotools
386
387 */

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)