Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(183)

Side by Side Diff: src/site/articles/doc-comment-guidelines/index.markdown

Issue 118633004: New TOC for dart-by-example page (Closed) Base URL: https://github.com/dart-lang/dartlang.org.git@master
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 --- 1 ---
2 layout: article 2 layout: article
3 title: "Guidelines for Dart Doc Comments" 3 title: "Guidelines for Dart Doc Comments"
4 rel: 4 rel:
5 author: kathy-walrath 5 author: kathy-walrath
6 description: "How we write doc comments for the Dart APIs." 6 description: "How we write doc comments for the Dart APIs."
7 has-permalinks: true 7 has-permalinks: true
8 article: 8 article:
9 written_on: 2012-11-01 9 written_on: 2012-11-01
10 collection: everyday-dart 10 collection: everyday-dart
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 70
71 The description should help the reader understand 71 The description should help the reader understand
72 whether this bit of API might be useful to them, 72 whether this bit of API might be useful to them,
73 compared to similar sounding API. 73 compared to similar sounding API.
74 Never just repeat the API name; 74 Never just repeat the API name;
75 try to restate it to give more information 75 try to restate it to give more information
76 than the name alone provides. 76 than the name alone provides.
77 Avoid links when possible. 77 Avoid links when possible.
78 78
79 79
80 #### Functions and methods 80 #### Functions and methods
81 {:.no_toc}
81 82
82 Function/method descriptions begin with a **third-person verb**. 83 Function/method descriptions begin with a **third-person verb**.
83 84
84 Examples: 85 Examples:
85 86
86 * `Returns true if every element of this collection satisfies the predicate [f]. ` 87 * `Returns true if every element of this collection satisfies the predicate [f]. `
87 * `Starts the stopwatch.` 88 * `Starts the stopwatch.`
88 89
89 90
90 #### Variables, getters, and setters 91 #### Variables, getters, and setters
92 {:.no_toc}
91 93
92 Static/instance variable and getter/setter descriptions are **noun phrases**. 94 Static/instance variable and getter/setter descriptions are **noun phrases**.
93 95
94 If there’s both a setter and a getter, comment only the getter. 96 If there’s both a setter and a getter, comment only the getter.
95 That way, it’ll be treated as a variable. 97 That way, it’ll be treated as a variable.
96 Don’t include the type, since that’s already in the signature. 98 Don’t include the type, since that’s already in the signature.
97 99
98 Example: 100 Example:
99 101
100 * `The number of days in the current month.` 102 * `The number of days in the current month.`
101 103
102 104
103 #### Classes 105 #### Classes
106 {:.no_toc}
104 107
105 Class descriptions are **noun phrases**. 108 Class descriptions are **noun phrases**.
106 109
107 Examples: 110 Examples:
108 111
109 * Possible description for [List](http://api.dartlang.org/dart_core/List.html): <br>`An indexable collection with a length, also known as an array.` 112 * Possible description for [List](http://api.dartlang.org/dart_core/List.html): <br>`An indexable collection with a length, also known as an array.`
110 113
111 * Possible description for [String](http://api.dartlang.org/dart_core/String.htm l): <br>`A basic string, implemented as an immutable sequence of UTF-16 code uni ts.` 114 * Possible description for [String](http://api.dartlang.org/dart_core/String.htm l): <br>`A basic string, implemented as an immutable sequence of UTF-16 code uni ts.`
112 115
113 116
114 #### Libraries 117 #### Libraries
118 {:.no_toc}
115 119
116 Library descriptions are **noun phrases**. 120 Library descriptions are **noun phrases**.
117 121
118 Examples: 122 Examples:
119 123
120 * Possible description for [dart:core](http://api.dartlang.org/dart_core.html): <br>`Core functionality that's automatically imported into every Dart program.` 124 * Possible description for [dart:core](http://api.dartlang.org/dart_core.html): <br>`Core functionality that's automatically imported into every Dart program.`
121 125
122 * Possible description for [dart:collection](http://api.dartlang.org/dart_collec tion.html): <br>`Data structures for managing collections of objects.` 126 * Possible description for [dart:collection](http://api.dartlang.org/dart_collec tion.html): <br>`Data structures for managing collections of objects.`
123 127
124 128
125 129
126 ### The rest of the doc comment 130 ### The rest of the doc comment
127 131
128 Subsequent paragraphs explain return values, 132 Subsequent paragraphs explain return values,
129 what arguments you can specify, side effects, 133 what arguments you can specify, side effects,
130 exceptions that users might want to catch, related APIs, and so on. 134 exceptions that users might want to catch, related APIs, and so on.
131 135
132 Be sure to provide **code examples** for the most common uses of the API, 136 Be sure to provide **code examples** for the most common uses of the API,
133 and **links** to documents that provide more information. 137 and **links** to documents that provide more information.
134 138
135 139
136 ## Markup 140 ## Markup
137 141
138 Format your text using the markup 142 Format your text using the markup
139 specified in section 15.1.2 of the 143 specified in section 15.1.2 of the
140 [Dart Language Specification](/docs/spec/). 144 [Dart Language Specification](/docs/spec/).
141 Although dartdoc currently recognizes some additional markdown 145 Although dartdoc currently recognizes some additional markdown
142 (as noted below), 146 (as noted below),
143 it might not always. 147 it might not always.
144 148
145 **When in doubt, format less.** 149 **When in doubt, format less.**
146 You'll be less likely to break the docs, and someone else can always add formatt ing. 150 You'll be less likely to break the docs, and someone else can always add formatt ing.
147 151
148 152
149 ### Links 153 ### Links
150 154
151 You can link to Dart identifiers, 155 You can link to Dart identifiers,
152 of which constructors are a special case, 156 of which constructors are a special case,
153 or to any URI you choose. 157 or to any URI you choose.
154 158
155 #### Identifier 159 #### Identifier
160 {:.no_toc}
156 161
157 `[id]` _or_ `[id](uri)` 162 `[id]` _or_ `[id](uri)`
158 163
159 If _id_ is the name of a class, the generated link points at the class, 164 If _id_ is the name of a class, the generated link points at the class,
160 even if the class has a constructor of the same name. 165 even if the class has a constructor of the same name.
161 If you specify _uri_, it must be the URI of a dart library _L_, 166 If you specify _uri_, it must be the URI of a dart library _L_,
162 and _id_ must a name declared in the exported namespace of _L_. 167 and _id_ must a name declared in the exported namespace of _L_.
163 168
164 #### Constructor 169 #### Constructor
170 {:.no_toc}
165 171
166 `[new c]` _or_ `[new c](uri)` 172 `[new c]` _or_ `[new c](uri)`
167 173
168 174
169 #### Hyperlink 175 #### Hyperlink
176 {:.no_toc}
170 177
171 `[text](uri)` _or_ `<uri>` 178 `[text](uri)` _or_ `<uri>`
172 179
173 Note: _uri_ is the URI to link to; 180 Note: _uri_ is the URI to link to;
174 _text_ is the string to be displayed instead of the URI. 181 _text_ is the string to be displayed instead of the URI.
175 182
176 183
177 ### Block styles 184 ### Block styles
178 185
179 #### Paragraph 186 #### Paragraph
187 {:.no_toc}
180 188
181 Use _a blank line_ to denote the end of a paragraph. 189 Use _a blank line_ to denote the end of a paragraph.
182 190
183 #### Code block 191 #### Code block
192 {:.no_toc}
184 193
185 Use four blank spaces _after the line's comment characters,_ 194 Use four blank spaces _after the line's comment characters,_
186 which means **five spaces** after the * or / 195 which means **five spaces** after the * or /
187 (since they're always followed by a space). 196 (since they're always followed by a space).
188 Example: 197 Example:
189 198
190 {% prettify dart %} 199 {% prettify dart %}
191 /** 200 /**
192 * ... 201 * ...
193 * For example: 202 * For example:
194 * 203 *
195 * Future&lt;int> future = getFutureFromSomewhere(); 204 * Future&lt;int> future = getFutureFromSomewhere();
196 * future.then((value) { 205 * future.then((value) {
197 * print("I received the number $value"); 206 * print("I received the number $value");
198 * }); 207 * });
199 * ... 208 * ...
200 */ 209 */
201 {% endprettify %} 210 {% endprettify %}
202 211
203 #### Header 212 #### Header
213 {:.no_toc}
204 214
205 <pre>## header text until newline</pre> 215 <pre>## header text until newline</pre>
206 216
207 Lower level heads (such as `###`) 217 Lower level heads (such as `###`)
208 are currently implemented but not specified. 218 are currently implemented but not specified.
209 219
210 220
211 #### Bulleted (unordered) list item 221 #### Bulleted (unordered) list item
222 {:.no_toc}
212 223
213 <pre>* item continues until next list item or blank line</pre> 224 <pre>* item continues until next list item or blank line</pre>
214 225
215 The line before the first bulleted list item must be blank. 226 The line before the first bulleted list item must be blank.
216 227
217 228
218 #### Numbered (ordered) list item 229 #### Numbered (ordered) list item
230 {:.no_toc}
219 <pre>1. item continues until next list item or blank line 231 <pre>1. item continues until next list item or blank line
220 2. next item</pre> 232 2. next item</pre>
221 233
222 The specification states that items aren't autonumbered. 234 The specification states that items aren't autonumbered.
223 Use `2.` for item #2, `3.` for item #3, and so on. 235 Use `2.` for item #2, `3.` for item #3, and so on.
224 236
225 237
226 ### Inline styles 238 ### Inline styles
227 239
228 #### Code font 240 #### Code font
241 {:.no_toc}
229 242
230 <code>`code`</code> _(note the backquotes) 243 <code>`code`</code> _(note the backquotes)
231 or_ 244 or_
232 <code>[:code:]</code> 245 <code>[:code:]</code>
233 246
234 Avoid code font unless it’s (1) a big chunk of code or 247 Avoid code font unless it’s (1) a big chunk of code or
235 (2) necessary to prevent confusion. 248 (2) necessary to prevent confusion.
236 249
237 #### Italics 250 #### Italics
251 {:.no_toc}
238 252
239 `_single underscore_` 253 `_single underscore_`
240 _or_ 254 _or_
241 `*single asterisk*` 255 `*single asterisk*`
242 256
243 It's possible that when the specification is clarified, 257 It's possible that when the specification is clarified,
244 a single asterisk will mean boldface. 258 a single asterisk will mean boldface.
245 259
246 #### Boldface 260 #### Boldface
261 {:.no_toc}
247 262
248 `**double asterisk**` 263 `**double asterisk**`
249 _or_ 264 _or_
250 `__double underscore__` 265 `__double underscore__`
251 266
252 The specification doesn't include double asterisk and underscore, 267 The specification doesn't include double asterisk and underscore,
253 and it's possible that a single asterisk will mean boldface. 268 and it's possible that a single asterisk will mean boldface.
254 269
255 Here's an example of a warning: 270 Here's an example of a warning:
256 271
(...skipping 17 matching lines...) Expand all
274 * Use "this" instead of "the" 289 * Use "this" instead of "the"
275 when referring to an object created from the current class. 290 when referring to an object created from the current class.
276 Example: 291 Example:
277 Adds an item to this list. 292 Adds an item to this list.
278 293
279 294
280 ## Resources 295 ## Resources
281 296
282 * [Comments](/articles/style-guide/#comments) 297 * [Comments](/articles/style-guide/#comments)
283 section of the Dart Style Guide 298 section of the Dart Style Guide
284 * dart:math API doc 299 * dart:math API doc
285 ([generated doc](http://api.dartlang.org/dart_math.html), 300 ([generated doc](http://api.dartlang.org/dart_math.html),
286 [source code](http://code.google.com/p/dart/source/browse/branches/bleeding_ed ge/dart/sdk/lib/math/math.dart)) 301 [source code](http://code.google.com/p/dart/source/browse/branches/bleeding_ed ge/dart/sdk/lib/math/math.dart))
287 * [dart-doc-testing](https://github.com/kwalrath/dart-doc-testing) project 302 * [dart-doc-testing](https://github.com/kwalrath/dart-doc-testing) project
288 ([generated doc](http://kwalrath.github.com/dart-doc-testing/comment_test/Comm entTester.html), 303 ([generated doc](http://kwalrath.github.com/dart-doc-testing/comment_test/Comm entTester.html),
289 [source code](https://github.com/kwalrath/dart-doc-testing/blob/master/Comment Test.dart)) 304 [source code](https://github.com/kwalrath/dart-doc-testing/blob/master/Comment Test.dart))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698