@@ -10,43 +10,65 @@ previous-page: declarations
10
10
11
11
It is important to provide documentation for all packages, classes,
12
12
traits, methods, and other members. Scaladoc generally follows the
13
- conventions of Javadoc, however there are many additional features to
14
- make writing scaladoc simpler .
13
+ conventions of Javadoc, but provides many additional features that
14
+ simplify writing documentation for Scala code .
15
15
16
16
In general, you want to worry more about substance and writing style
17
- than in formatting. Scaladocs need to be useful to new users of the code
17
+ than about formatting. Scaladocs need to be useful to new users of the code
18
18
as well as experienced users. Achieving this is very simple: increase
19
19
the level of detail and explanation as you write, starting from a terse
20
20
summary (useful for experienced users as reference), while providing
21
21
deeper examples in the detailed sections (which can be ignored by
22
22
experienced users, but can be invaluable for newcomers).
23
23
24
- The general format for a Scaladoc comment should be as follows:
24
+ The Scaladoc tool does not mandate a documentation comment style.
25
25
26
- /** This is a brief description of what's being documented.
26
+ The following examples demonstrate a single line summary followed
27
+ by detailed documentation, in the three common styles of indentation.
28
+
29
+ Javadoc style:
30
+
31
+ /**
32
+ * Provides a service as described.
27
33
*
28
- * This is further documentation of what we're documenting. It should
29
- * provide more details as to how this works and what it does.
34
+ * This is further documentation of what we're documenting.
35
+ * Here are more details about how it works and what it does.
30
36
*/
31
- def myMethod = {}
37
+ def member: Unit = ()
38
+
39
+ Scaladoc style, with gutter asterisks aligned in column two:
40
+
41
+ /** Provides a service as described.
42
+ *
43
+ * This is further documentation of what we're documenting.
44
+ * Here are more details about how it works and what it does.
45
+ */
46
+ def member: Unit = ()
47
+
48
+ Scaladoc style, with gutter asterisks aligned in column three:
49
+
50
+ /** Provides a service as described.
51
+ *
52
+ * This is further documentation of what we're documenting.
53
+ * Here are more details about how it works and what it does.
54
+ */
55
+ def member: Unit = ()
32
56
33
- An alternative Scaladoc comment style right-aligns the column of asterisks
34
- under the second asterisk, in the third column.
35
- The Scaladoc tool also accepts Javadoc comment formatting,
36
- with text following the single asterisks, separated by a single space.
37
57
Because the comment markup is sensitive to whitespace,
38
58
the tool must be able to infer the left margin.
39
59
40
- For methods and other type members where the only documentation needed
41
- is a simple, short description, a one-line format can be used:
60
+ When only a simple, short description is needed, a one-line format can be used:
42
61
43
62
/** Does something very simple */
44
- def simple = {}
63
+ def simple: Unit = ()
64
+
65
+ Note that, in contrast to the Javadoc convention, the text in
66
+ the Scaladoc styles begins on the first line of the comment.
67
+ This format saves vertical space in the source file.
45
68
46
- Note that, in contrast to the Javadoc convention, the text begins
47
- on the first line of the comment but that subsequent text remains aligned.
48
- In particular, text is aligned on a multiple of two columns,
49
- since Scala source is usually indented by two columns.
69
+ In either Scaladoc style, all lines of text are aligned on column five.
70
+ Since Scala source is usually indented by two spaces,
71
+ the text aligns with source indentation in a way that is visually pleasing.
50
72
51
73
See the
52
74
[ AuthorDocs] ( https://wiki.scala-lang.org/display/SW/Writing+Documentation )
0 commit comments