Skip to content

Commit f51b111

Browse files
committed
Merge pull request #4109 from bordeltabernacle/add/func_args
Add section about function arguments to 'Writing Documentation'
2 parents 88ffb46 + ac3bbad commit f51b111

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

lib/elixir/pages/Writing Documentation.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,20 @@ The function above can still be invoked as `MyApp.Sample.add(1, 2)`. Not only th
7777

7878
* 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.
7979

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+
8094
## Documentation != Comments
8195

8296
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)