Debian Codegraph @

doc/developers/writing-documentation.html

raw symbols ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
2 "https://www.w3.org/TR/html4/loose.dtd">
3 <html>
4 <head>
5 <meta http-equiv="Content-type" content="text/html;charset=UTF-8">
6 <title>Writing documentation</title>
7 <link href="../screen.css" rel="StyleSheet">
8 <meta name="copyright" content="Copyright (C) 1998 - 2023 by the deal.II Authors">
9 <meta name="keywords" content="deal dealii finite elements fem triangulation">
10 <meta http-equiv="content-language" content="en">
11 </head>
12 <body>
13
14 <h1>Writing Documentation</h1>
15
16 <p>
17 It is our firm belief that software can only be successful if it
18 is properly documented. Too many academic software projects die
19 prematurely once their creators leave the university or the
20 workgroup in which the software was developed, since with their
21 creators also knowledge of internal structures, interfaces, and
22 the valuable bag of tricks leaves, a gap that can not be closed by
23 reading sources, trial-and-error, and guessing.
24 </p>
25
26 <p>
27 The <acronym>deal.II</acronym> project has therefore from its
28 infancy adopted a policy that every aspect of the interface
29 needs to be well-documented before its inclusion into the
30 source tree. Since we have found that it is impossible to keep
31 documentation up-to-date if it is not written directly into the
32 program code, we write the documentation directly at the place of
33 declaration of a function or class and use automatic tools to
34 extract this information from the files and process it into HTML
35 for our web-pages, or LaTeX for printing.
36 </p>
37
38 <p>
39 In addition to the API documentation, we maintain a series of
40 <a href="../doxygen/deal.II/Tutorial.html" target="_top">
41 well-documented example programs</a>, which also follow a certain
42 ``literate programming'' style in that the explanations of what
43 is happening are integrated into the program source by means of
44 comments, and are extracted by small scripts.
45 </p>
46
47 <p>
48 This document first explains the basics of
49 <a href="#API" target="body">documenting the API</a> and then of
50 <a href="#examples" target="body">writing example programs</a>.
51 </p>
52
53
54 <a name="API"></a>
55 <h2>Writing API documentation</h2>
56
57 <p>
58 In order to extract documentation from the header files of the
59 project, we use
60 <a href="https://www.doxygen.org/" target="_top">doxygen</a>.
61 It requires that documentation is written in a form which
62 closely follows the
63 <a href="https://java.sun.com/products/jdk/javadoc/index.html" target="_top">
64 JavaDoc</a> standard.
65 </p>
66
67
68 <h3>Basic layout of documentation</h3>
69
70 <p>
71 Basically, every declaration, whether class or member
72 function/variable declaration, global function or namespace, may
73 be preceded by a comment of the following form:
74 </p>
75 <pre>
76 /**
77 * This is an example documentation.
78 */
79 class TestClass
80 {
81 public:
82 /**
83 * Constructor
84 */
85 TestClass ();
86
87 /**
88 * Example function
89 */
90 virtual void test () const = 0;
91
92 /**
93 * Member variable
94 */
95 const unsigned int abc;
96 };
97 </pre>
98 <p>
99 <acronym>doxygen</acronym> will then generate a page for the class
100 <code>TestClass</code> and document each of the member functions
101 and variables.
102 </p>
103
104
105 <h3>Extended Layout</h3>
106
107 <p>
108 In order to allow better structured output for long comments,
109 doxygen supports a great number of tags for enumerations,
110 sectioning, markup, and other fields. We encourage you to take a
111 look at the <a href="https://www.doxygen.org/"
112 target="_top">doxygen webpage</a> to get an overview. However,
113 here is a brief summary of the most often used features:
114 </p>
115 <ul>
116 <li> <em>Virtual functions:</em>
117 Do not document virtual functions in derived classes, if there
118 is nothing different from the base class. If a virtual
119 function is documented in a base class, doxygen will
120 automatically copy this documentation to the derived
121 classes. This mechanism is interrupted, if a documentation
122 block is found in the derived class.
123
124 <li> <em>Itemized lists:</em>
125 By writing comments like the following,
126 <pre>
127 /**
128 * &lt;ul&gt;
129 * &lt;li&gt; foo
130 * &lt;li&gt; bar
131 * &lt;/ul&gt;
132 */
133 </pre>
134 you can get itemized lists both in the online and printed
135 documentation:
136 <ul>
137 <li> foo
138 <li> bar
139 </ul>
140
141 <p>
142 In other words, one can use standard HTML tags for this
143 task. Likewise, you can get numbered lists by using the
144 respective HTML tags <code>&lt;ol&gt;</code>.
145 </p>
146
147 <li> <em>Verbatim output:</em>
148 <p>
149 If you write comments like this,
150 </p>
151 <pre>
152 /**
153 * @verbatim
154 * void foobar ()
155 * {
156 * i = 0;
157 * }
158 * @endverbatim
159 */
160 </pre>
161 you will get the lines between the verbatim environment with
162 the same formatting and in typewriter font:
163 <pre>
164 void foobar ()
165 {
166 i = 0;
167 }
168 </pre>
169 This is useful if you want to include small sample code snippets
170 into your documentation. In particular, it is important that
171 the formatting is preserved, which is not the case for all
172 other text.
173
174 <li> <em>Typewriter font:</em>
175 <p>In order to use typewriter font for instance for function
176 arguments or variables, use the <code>&lt;code&gt;</code> HTML
177 tag. For a single word, you can also use the form <code>@p
178 one_word_without_spaces</code>. The <code>&lt;tt&gt;</code> is obsolete in HTML5</p>
179
180 <p>
181 If you refer to member variables and member functions
182 <acronym>doxygen</acronym> has better options than this: use
183 <tt>function_name()</tt> to reference member functions and
184 <tt>#variable_name</tt> for member variables to create links
185 automatically. Refer to the documentation of <a
186 href="https://www.doxygen.org"><acronym>doxygen</acronym></a> to
187 get even more options for global variables.
188 </p>
189
190 <li> <em>Emphasis:</em>
191 <p>
192 To generate output in italics, use the <code>@em
193 one_word_without_spaces</code> tag or the <tt>&lt;em&gt;</tt>
194 HTML tag. To generate boldface, use <tt>&lt;b&gt;</tt>
195 </p>
196
197 <li> <em>Formul&aelig;:</em>
198 <p>
199 For simple and short formul&aelig; use the <tt>&lt;i&gt;</tt>
200 HTML tag. Note that you can use <tt>&lt;sub&gt;</tt> and
201 <tt>&lt;sup&gt;</tt> to get subscripts an superscripts,
202 respectively. Only for longer formul&aelig; use
203 <tt>$formula$</tt> to generate a LaTeX formula which will then be
204 included as a graphical image.
205 </p>
206
207 <li> <em>Sections:</em>
208 <p>
209 Sections in class and function documentations can be
210 generated using the <tt>&lt;hN&gt;</tt> HTML headline
211 tags. Headlines inside class documentation should start at
212 level 3 (<tt>&lt;h3&gt;</tt>) to stay consistent with the
213 structure of the <acronym>doxygen</acronym> output.
214 </p>
215
216 <p>
217 Sections cannot be referenced, unless you add a <tt>&lt;A
218 NAME="..."&gt;</tt> name anchor to them. If you really have
219 to do this, please make sure the name does not interfere with
220 <acronym>doxygen</acronym> generated anchors.
221 </p>
222
223 <li> <em>Exclusion from documentation:</em>
224 <p> <acronym>doxygen</acronym> sometimes has problems with inlined
225 functions of template classes. For these cases (and other cases of
226 parts of the code to be excluded from documentation), we define a
227 preprocessor symbol <tt>DOXYGEN</tt> when running
228 <acronym>doxygen</acronym>. Therefore, the following template can be
229 used to avoid documentation:</p>
230 <pre>
231 /* documented code here */
232
233 #ifndef DOXYGEN
234
235 /* code here is compiled, but ignored by doxygen */
236
237 #endif // DOXYGEN
238 </pre>
239 </ul>
240
241
242 <a name="examples"></a>
243 <h2>Writing example programs for the tutorial</h2>
244
245 <p>
246 Tutorial programs consist of an introduction, a well documented
247 code, and a section that shows the output and numerical results
248 of running the program. These three parts are written in separate
249 files: for the <code>step-xx</code> program, for example, they
250 would be in the
251 files <code>dealii/examples/step-xx/doc/intro.dox</code>,
252 <code>dealii/examples/step-xx/step-xx.cc</code> and
253 <code>dealii/examples/step-xx/doc/results.dox</code>. There are a
254 number of scripts that then process and concatenate these three
255 different files and send them through doxygen for generation of
256 HTML output. In general, if you want to see how certain markup
257 features can be used, it is worthwhile looking at the existing
258 tutorial program pages and the files they are generated from.
259 </p>
260
261 <h3>The introduction</h3>
262 <p>
263 The introduction, as well as the results section, will be
264 processed as if they were doxygen comments. In other words, all
265 the usual doxygen markup will work in these sections, including
266 latex formulas, though the format for the formula environment is
267 a bit awkward. Since it takes much longer to run doxygen for all
268 of deal.II than to run latex, most of the lengthier
269 introductions are just written in latex (with a minimal amount
270 of markup) and later converted into doxygen format. One thing to
271 be aware of is that you can't reference formulas in doxygen, so
272 you have to work around that using text rather than formula
273 numbers.
274 </p>
275
276 <p>
277 More important is what goes into the introduction. Typically,
278 this would first be a statement of the problem that we want to
279 solve. Take a look, for example, at
280 the <a href="../doxygen/deal.II/step_22.html"
281 target="_top">step-22</a>
282 or <a href="../doxygen/deal.II/step_31.html"
283 target="_top">step-31</a> tutorial programs. Then come a few
284 sections in which we would discuss in mathematical terms the
285 algorithms that we want to use; this could, for example, include
286 the time stepping, discretization, or solver
287 approaches. <a href="../doxygen/deal.II/step_22.html"
288 target="_top">step-22</a>
289 and <a href="../doxygen/deal.II/step_31.html"
290 target="_top">step-31</a> are again good, if lengthy, examples
291 for this.
292 </p>
293
294 <p>
295 On the other hand, if a program is an extension of a previous
296 program, these things need not be repeated: you would just
297 reference the previous program. For
298 example, <a href="../doxygen/deal.II/step_16.html"
299 target="_top">step-16</a> does not talk about adaptive meshes
300 any more &mdash; it
301 extends <a href="../doxygen/deal.II/step_6.html"
302 target="_top">step-6</a> and simply refers there for
303 details. Likewise, <a href="../doxygen/deal.II/step_32.html"
304 target="_top">step-32</a> simply refers
305 to <a href="../doxygen/deal.II/step_31.html"
306 target="_top">step-31</a> for the problem statement and basic
307 algorithm and simply focuses on those parts that are new
308 compared to
309 <a href="../doxygen/deal.II/step_31.html" target="_top">step-31</a>.
310 </p>
311
312 <p>
313 The purpose of the introduction is to explain what the program
314 is doing. It should set the mindset so that when you read
315 through the code you already know <i>why</i> we are doing
316 something. You may not yet know <i>how</i> this done, but this
317 is what the documentation within the code is doing. At least you
318 don't have to wonder any more why we are building up this
319 complicated preconditioner &mdash; we've already discussed this
320 in the introduction.
321 </p>
322
323 <p>
324 If it helps the understanding, the introduction can refer to
325 particular pieces of code (but doesn't have to). For example,
326 the introduction to <a href="../doxygen/deal.II/step_20.html"
327 target="_top">step-20</a> has pretty lengthy code snippets that
328 explain how to implement a general interface of operators that
329 may or may not be matrices. This would be awkward to do within
330 the code since in the code the view is somewhat smaller (you
331 have to have complete parameter lists, follow the syntax of the
332 programming language, etc, all of which obscures the things one
333 wants to discuss when giving a broad overview related to
334 particular C++ constructs). On the other hand, showing code
335 snippets in the introduction risks duplicating code in two
336 places, which will eventually get out of synch. Consequently,
337 this instrument should only be used sparingly.
338 </p>
339
340
341 <h3>The actual code</h3>
342 <p>
343 At present, the tools that extract information from the actual example
344 programs code are rather dumb. They are, to be precise, the Perl
345 scripts located in the directory of the
346 <code>deal.II/doc/doxygen/scripts</code> tree, where
347 the <code>.cc</code> files of the tutorial programs are converted
348 into doxygen input files. In essence, what these scripts do is to
349 create doxygen input that contains the comments of the program as
350 text, and the actual code of the programs as code snippets. You
351 can see this when you look at the pages for each of the tutorials
352 where the code is indented relative to the text.
353 </p>
354
355 <p>
356 The whole thing being interpreted by doxygen means that you can
357 put anything doxygen understands into comments. This includes,
358 for example references to classes or members in the library (in
359 fact, you just need to write their name out and doxygen will
360 automatically link them), formulas, lists, etc. It all will come
361 out as if you had written comments for doxygen in the first
362 place.
363 </p>
364
365 <p>
366 The bigger question is <i>how</i> to write the comments that
367 explain what's going on in individual code blocks. Many years
368 back we wrote them so that every line or every two lines had
369 their own comment. You can still see this in some of the older
370 tutorial programs, though many of them have in the meantime been
371 converted to a newer style: it turns out that if you have
372 comments so frequently, it becomes hard to follow the flow of an
373 algorithm. In essence, you know exactly what each line does, but
374 you can't get an overview of what the function as a whole
375 does. But that's exactly the point of the tutorial programs, of
376 course!
377 </p>
378
379 <p>
380 So the way we now believe tutorial programs should be written is
381 to have comments for each logical block. For example,
382 the <code>solve()</code> function in many of the programs is
383 relatively straightforward and has at most a dozen lines of
384 code. So put a comment in front of the function that explains
385 all the things that are going on in the function, and then show
386 the function without comments in it &mdash; this way, a reader
387 will read through the half or full page of documentation
388 understanding the big picture, and can then see the whole
389 function all at once on a single screen without having to scroll
390 up and down. In the old way, the code would be spread out over a
391 couple pages, with comments between almost any two lines, making
392 it hard to see how it all fits together.
393 </p>
394
395 <p>
396 It is somewhat subjective how much code you should leave in each
397 block that you document separately. It might be a single line if
398 something really important and difficult happens there, but most
399 of the time it's probably more along the lines of 6 to 12 lines
400 &mdash; a small enough part of the code so that it's easy enough
401 to grasp by looking at it all at once, but large enough that it
402 contributes a significant part or all of an algorithm.
403 </p>
404
405
406 <h3>The results section</h3>
407
408 <p>
409 The results section should show (some of) the output of a
410 program, such as the console output and/or a visualization of
411 graphical output. It should also contain a brief discussion of
412 this output. It is intended to demonstrate what the program
413 does, so that a reader can see what happens if the program were
414 executed without actually running it. It helps to show a few
415 nice graphics there.
416 </p>
417
418 <p>
419 This section needs not be overly comprehensive. If the program
420 is the implementation of a method that's discussed in an
421 accompanying paper, it's entirely ok to say "for further
422 numerical results, see ...".
423 </p>
424
425 <p>
426 Like the introduction, the results section file is copied
427 verbatim into input for doxygen, so all doxygen markup is
428 possible there.
429 </p>
430
431
432 <hr />
433 <div class="right">
434 <a href="https://validator.w3.org/check?uri=referer" target="_top">
435 <img style="border:0" src="https://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!"></a>
436 <a href="https://jigsaw.w3.org/css-validator/check/referer" target="_top">
437 <img style="border:0;width:88px;height:31px" src="https://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!"></a>
438 </div>
439
440 </body>
441 </html>