@@ -98,6 +98,63 @@ check [the official build status on Travis-CI](https://travis-ci.org/elixir-lang
9898With tests running and passing, you are ready to contribute to Elixir and
9999send your pull requests.
100100
101+ ## Contributing Documentation
102+
103+ Code documentation (` @doc ` , ` @moduledoc ` , ` @typedoc ` ) has a special convention:
104+ the first paragraph is considered to be a short summary.
105+
106+ For functions, macros and callbacks say what it will do. For example write
107+ something like:
108+
109+ ``` elixir
110+ @doc """
111+ Return only those elements for which `fun` is true.
112+
113+ ...
114+ """
115+ def filter (collection, fun) .. .
116+ ```
117+
118+ For modules, records, protocols and types say what it is. For example write
119+ something like:
120+
121+ ```elixir
122+ @doc """
123+ Information about a file.
124+
125+ ...
126+ """
127+ defrecord File .Stat .. .
128+ ```
129+
130+ Keep in mind that the first paragraph might show up in a summary somewhere, long
131+ texts in the first paragraph create very ugly summaries. As a rule of thumb
132+ anything longer than 80 characters is too long.
133+
134+ Try to keep unneccesary details out of the first paragraph, it' s only there to
135+ give a user a quick idea of what the documented "thing" does/is. The rest of the
136+ documentation string can contain the details, for example when a value and when
137+ `nil` is returned.
138+
139+ If possible include examples, preferably in a form that works with doctests. For
140+ example:
141+
142+ ```elixir
143+ @doc """
144+ Return only those elements for which `fun` is true.
145+
146+ ## Examples
147+
148+ iex> Enum.filter([1, 2, 3], fn(x) -> rem(x, 2) == 0 end)
149+ [2]
150+
151+ """
152+ def filter(collection, fun) ...
153+ ```
154+
155+ This makes it easy to test the examples so that they don' t go stale and examples
156+ are often a great help in explaining what a function does.
157+
101158## Pull requests
102159
103160Good pull requests - patches, improvements, new features - are a fantastic
0 commit comments