Skip to content

Commit f7a1d27

Browse files
author
José Valim
committed
Amend writing docs
1 parent f51b111 commit f7a1d27

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

lib/elixir/pages/Writing Documentation.md

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,18 @@ Documentation in Elixir is usually attached to module attributes. Let's see an e
3636

3737
The `@moduledoc` attribute is used to attach documentation to the module. `@doc` is used before a function to attach documentation to it. Besides the attributes above, `@typedoc` can also be used to attach documentation to types defined as part of typespecs.
3838

39+
## Function Arguments
40+
41+
When documenting a function, argument names are inferred by the compiler. For example:
42+
43+
def size(%HashDict{size: size}) do
44+
size
45+
end
46+
47+
The compiler will infer this argument as `hash_dict`. Sometimes the inference will be suboptimal, specially if the function contains multiple clauses with the argument matching on different values each time. You can specify the proper names for documentation by using a bodyless clause:
48+
49+
def size(dict)
50+
3951
## Recommendations
4052

4153
There are a couple tips we recommend developers to follow when writing documentation:
@@ -77,20 +89,6 @@ The function above can still be invoked as `MyApp.Sample.add(1, 2)`. Not only th
7789

7890
* Start the function name with underscores, for example, `__add__/2`, and add `@doc false`. The compiler does not import functions with underscore and the underscore will tell users to be wary of using it.
7991

80-
## Function Arguments
81-
82-
When documenting a function, argument names are inferred by the compiler. This can be changed by specifying your preferred argument name. For example:
83-
84-
def size(%HashDict{size: size}) do
85-
size
86-
end
87-
88-
The compiler will infer this argument as `hash_dict`, whereas if you'd prefer it to be, for instance, `dict`, you can write it as so:
89-
90-
def size(%HashDict{size: size} = _dict) do
91-
size
92-
end
93-
9492
## Documentation != Comments
9593

9694
Elixir makes the difference between documentation and code comments. Documentation are for users of your API, be it your co-worker or your future self. Modules and functions must always be documented if they are part of your application public interface (API).

0 commit comments

Comments
 (0)