1 <?xml version="1.0" encoding="utf-8"?><!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'><html lang="en" xmlns="http://www.w3.org/1999/xhtml">
3 <title>Twisted Documentation: Twisted Writing Standard</title>
4 <link href="../../howto/stylesheet.css" rel="stylesheet" type="text/css"/>
8 <h1 class="title">Twisted Writing Standard</h1>
9 <div class="toc"><ol><li><a href="#auto0">General style</a></li><li><a href="#auto1">Evangelism and usage documents</a></li><li><a href="#auto2">Descriptions of features</a></li><li><a href="#auto3">Linking</a></li><li><a href="#auto4">Introductions</a></li><ul><li><a href="#auto5">Introductory paragraph</a></li><li><a href="#auto6">Description of target audience</a></li><li><a href="#auto7">Goals of document</a></li></ul><li><a href="#auto8">Example code</a></li><li><a href="#auto9">Conclusions</a></li></ol></div>
13 <p>The Twisted writing standard describes the documentation writing
14 styles we prefer in our documentation. This standard applies particularly
15 to howtos and other descriptive documentation.</p>
17 <p>This document should be read with the <a href="doc-standard.html" shape="rect">documentation standard</a>, which describes
18 markup style for the documentation.</p>
20 <p>This document is meant to help Twisted documentation authors produce
21 documentation that does not have the following problems:</p>
24 <li>misleads users about what is good Twisted style;</li>
25 <li>misleads users into thinking that an advanced howto is an introduction
26 to writing their first Twisted server; and</li>
27 <li>misleads users about whether they fit the document's target audience:
28 for example, that they are able to use enterprise without knowing how to
29 write SQL queries.</li>
32 <h2>General style<a name="auto0"/></h2>
34 <p>Documents should aim to be clear and concise, allowing the API
35 documentation and the example code to tell as much of the story as they
36 can. Demonstrations and where necessary supported arguments should always
37 preferred to simple statements ("here is how you would simplify this
38 code with Deferreds" rather than "Deferreds make code
41 <p>Documents should be clearly delineated into sections and subsections.
42 Each of these sections, like the overall document, should have a single
43 clear purpose. This is most easily tested by trying to have meaningful
44 headings: a section which is headed by "More details" or
45 "Advanced stuff" is not purposeful enough. There should be
46 fairly obvious ways to split a document. The two most common are task
47 based sectioning and sectioning which follows module and class
50 <p>Documentation must use American English spelling, and where possible
51 avoid any local variants of either vocabulary or grammar. Grammatically
52 complex sentences should ideally be avoided: these make reading
53 unnecessarily difficult, particularly for non-native speakers.</p>
55 <h2>Evangelism and usage documents<a name="auto1"/></h2>
57 <p>The Twisted documentation should maintain a reasonable distinction
58 between "evangelism" documentation, which compares the Twisted
59 design or Twisted best practice with other approaches and argues for the
60 Twisted approach, and "usage" documentation, which describes the
61 Twisted approach in detail without comparison to other possible
64 <p>While both kinds of documentation are useful, they have different
65 audiences. The first kind of document, evangelical documents, is useful to
66 a reader who is researching and comparing approaches and seeking to
67 understand the Twisted approach or Twisted functionality in order to
68 decide whether it is useful to them. The second kind of document, usage
69 documents, are useful to a reader who has decided to use Twisted and
70 simply wants further information about available functions and
71 architectures they can use to accomplish their goal.</p>
73 <p>Since they have distinct audiences, evangelism and detailed usage
74 documentation belongs in separate files. There should be links between
75 them in 'Further reading' or similar sections.</p>
77 <h2>Descriptions of features<a name="auto2"/></h2>
79 <p>Descriptions of any feature added since release 2.0 of Twisted core
80 must have a note describing which release of which Twisted project they
81 were added in at the first mention in each document. If they are not yet
82 released, give them the number of the next minor release.</p>
84 <p>For example, a substantial change might have a version number added in
88 This document describes the Application infrastructure for deploying
89 Twisted applications <em>(added in Twisted 1.3)</em>.
92 <p>The version does not need to be mentioned elsewhere in the document
93 except for specific features which were added in subsequent releases,
94 which might should be mentioned separately.</p>
97 The simplest way to create a <code>.tac</code> file, SuperTac <em>(added
98 in Twisted Core 99.7)</em>...</blockquote>
100 <p>In the case where the usage of a feature has substantially changed, the
101 number should be that of the release in which the current usage became
102 available. For example:</p>
104 <blockquote> This document describes the Application infrastructure for
105 deploying Twisted applications <em>(updated[/substantially updated] in Twisted
106 2.7)</em>. </blockquote>
108 <h2>Linking<a name="auto3"/></h2>
110 <p>The first occurrence of the name of any module, class or function should
111 always link to the API documents. Subsequent mentions may or may not link
112 at the author's discretion: discussions which are very closely bound to a
113 particular API should probably link in the first mention in the given
116 <p>Links between howtos are encouraged. Overview documents and tutorials
117 should always link to reference documents and in depth documents. These
118 documents should link among themselves wherever it's needed: if you're
119 tempted to re-describe the functionality of another module, you should
120 certainly link instead.</p>
122 <h2>Introductions<a name="auto4"/></h2>
124 <p>The introductory section of a Twisted howto should immediately follow
125 the top-level heading and precede any subheadings.</p>
127 <p>The following items should be present in the introduction to Twisted
128 howtos: the introductory paragraph and the description of the target
131 <h3>Introductory paragraph<a name="auto5"/></h3>
133 <p>The introductory paragraph of a document should summarize what the
134 document is designed to present. It should use the both proper names for
135 the Twisted technologies and simple non-Twisted descriptions of the
136 technologies. For example, in this paragraph both the name of the technology
137 ("Conch") and a description ("SSH server") are used:</p>
140 This document describes setting up a SSH server to serve data from the
141 file system using Conch, the Twisted SSH implementation.
144 <p>The introductory paragraph should be relatively short, but should, like
145 the above, somewhere define the document's objective: what the reader
146 should be able to do using instructions in the document.</p>
148 <h3>Description of target audience<a name="auto6"/></h3>
150 <p>Subsequent paragraphs in the introduction should describe the target
151 audience of the document: who would want to read it, and what they should
152 know before they can expect to use your document. For example:</p>
156 The target audience of this document is a Twisted user who has a set of
157 filesystem like data objects that they would like to make available to
158 authenticated users over SFTP.
162 Following the directions in this document will require that you are
163 familiar with managing authentication via the Twisted Cred system.
167 <p>Use your discretion about the extent to which you list assumed
168 knowledge. Very introductory documents that are going to be among a
169 reader's first exposure to Twisted will even need to specify that they
170 rely on knowledge of Python and of certain networking concepts (ports,
171 servers, clients, connections) but documents that are going to be sought
172 out by existing Twisted users for particular purposes only need to specify
173 other Twisted knowledge that is assumed.</p>
175 <p>Any knowledge of technologies that wouldn't be considered "core
176 Python" and/or "simple networking" need to be explicitly
177 specified, no matter how obvious they seem to someone familiar with the
178 technology. For example, it needs to be stated that someone using
179 enterprise should know SQL and should know how to set up and populate
180 databases for testing purposes.</p>
182 <p>Where possible, link to other documents that will fill in missing
183 knowledge for the reader. Linking to documents in the Twisted repository
184 is preferred but not essential.</p>
186 <h3>Goals of document<a name="auto7"/></h3>
188 <p>The introduction should finish with a list of tasks that the user can
189 expect to see the document accomplish. These tasks should be concrete
190 rather than abstract, so rather than telling the user that they will
191 "understand Twisted Conch", you would list the specific tasks
192 that they will see the document do. For example:</p>
196 This document will demonstrate the following tasks using Twisted Conch:
200 <li>creating an anonymous access read-only SFTP server using a filesystem
202 <li>creating an anonymous access read-only SFTP server using a proxy
203 backend connecting to an HTTP server; and</li>
204 <li>creating a anonymous access read and write SFTP server using a
205 filesystem backend.</li>
209 <p>In many cases this will essentially be a list of your code examples,
210 but it need not be. If large sections of your code are devoted to design
211 discussions, your goals might resemble the following:</p>
215 This document will discuss the following design aspects of writing Conch
220 <li>authentication of users; and</li>
221 <li>choice of data backends.</li>
226 <h2>Example code<a name="auto8"/></h2>
228 <p>Wherever possible, example code should be provided to illustrate a
229 certain technique or piece of functionality.</p>
231 <p>Example code should try and meet as many of the following requirements
235 <li>example code should be a complete working example suitable for copying
236 and pasting and running by the reader (where possible, provide a link to a
237 file to download);</li>
238 <li>example code should be short;</li>
239 <li>example code should be commented very extensively, with the assumption
240 that this code may be read by a Twisted newcomer;</li>
241 <li>example code should conform to the <a href="coding-standard.html" shape="rect">coding standard</a>; and</li>
242 <li>example code should exhibit 'best practice', not only for dealing with
243 the target functionality, but also for use of the application framework
247 <p>The requirement to have a complete working example will occasionally
248 impose upon authors the need to have a few dummy functions: in Twisted
249 documentation the most common example is where a function is needed to
250 generate a Deferred and fire it after some time has passed. An example
251 might be this, where <code class="API"><a href="http://twistedmatrix.com/documents/12.1.0/api/twisted.internet.task.deferLater.html" title="twisted.internet.task.deferLater">deferLater</a></code> is used to fire a callback
252 after a period of time:</p>
254 <pre class="python"><p class="py-linenumber">1
262 </p><span class="py-src-keyword">from</span> <span class="py-src-variable">twisted</span>.<span class="py-src-variable">internet</span> <span class="py-src-keyword">import</span> <span class="py-src-variable">task</span>, <span class="py-src-variable">reactor</span>
264 <span class="py-src-keyword">def</span> <span class="py-src-identifier">getDummyDeferred</span>():
265 <span class="py-src-string">"""
266 Dummy method which returns a deferred that will fire in 5 seconds with
268 """</span>
269 <span class="py-src-keyword">return</span> <span class="py-src-variable">task</span>.<span class="py-src-variable">deferLater</span>(<span class="py-src-variable">reactor</span>, <span class="py-src-number">5</span>, <span class="py-src-keyword">lambda</span> <span class="py-src-variable">x</span>: <span class="py-src-string">"RESULT"</span>)
272 <p>As in the above example, it is imperative to clearly mark that the
273 function is a dummy in as many ways as you can: using <code>Dummy</code> in
274 the function name, explaining that it is a dummy in the docstring, and
275 marking particular lines as being required to create an effect for the
276 purposes of demonstration. In most cases, this will save the reader from
277 mistaking this dummy method for an idiom they should use in their Twisted
280 <h2>Conclusions<a name="auto9"/></h2>
282 <p>The conclusion of a howto should follow the very last section heading
283 in a file. This heading would usually be called "Conclusion".</p>
285 <p>The conclusion of a howto should remind the reader of the tasks that
286 they have done while reading the document. For example:</p>
290 In this document, you have seen how to:
294 <li>set up an anonymous read-only SFTP server;</li>
295 <li>set up a SFTP server where users authenticate;</li>
296 <li>set up a SFTP server where users are restricted to some parts of the
297 filesystem based on authentication; and</li>
298 <li>set up a SFTP server where users have write access to some parts of
299 the filesystem based on authentication.</li>
303 <p>If appropriate, the howto could follow this description with links to
304 other documents that might be of interest to the reader with their
305 newfound knowledge. However, these links should be limited to fairly
306 obvious extensions of at least one of the listed tasks.</p>
310 <p><a href="../../howto/index.html">Index</a></p>
311 <span class="version">Version: 12.1.0</span>