Skip to content

Commit fa298e5

Browse files
committed
Show all Scaladoc options
Demonstrate the styles of indentation without prejudice.
1 parent b7db284 commit fa298e5

File tree

1 file changed

+41
-19
lines changed

1 file changed

+41
-19
lines changed

style/scaladoc.md

Lines changed: 41 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,43 +10,65 @@ previous-page: declarations
1010

1111
It is important to provide documentation for all packages, classes,
1212
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.
1515

1616
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
1818
as well as experienced users. Achieving this is very simple: increase
1919
the level of detail and explanation as you write, starting from a terse
2020
summary (useful for experienced users as reference), while providing
2121
deeper examples in the detailed sections (which can be ignored by
2222
experienced users, but can be invaluable for newcomers).
2323

24-
The general format for a Scaladoc comment should be as follows:
24+
The Scaladoc tool does not mandate a documentation comment style.
2525

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.
2733
*
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.
3036
*/
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 = ()
3256

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.
3757
Because the comment markup is sensitive to whitespace,
3858
the tool must be able to infer the left margin.
3959

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:
4261

4362
/** 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.
4568

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.
5072

5173
See the
5274
[AuthorDocs](https://wiki.scala-lang.org/display/SW/Writing+Documentation)

0 commit comments

Comments
 (0)