Skip to content

Commit 6b87a54

Browse files
committed
Clarify writing documentation guide, closes #10610
1 parent 72ec902 commit 6b87a54

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

lib/elixir/pages/writing-documentation.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,18 @@ Conveniently, Elixir allows developers to hide modules and functions from the do
127127
end
128128
end
129129

130-
However, keep in mind that adding `@doc false` does not make the function private. The function above can still be invoked as `MyApp.Sample.add(1, 2)`. Not only that, if `MyApp.Sample` is imported, the `add/2` function will also be imported into the caller. For those reasons, be cautious when adding `@doc false` to functions, instead use one of these two options:
130+
In case you don't want to hide a whole module, you can hide functions individually:
131+
132+
defmodule MyApp.Sample do
133+
@doc false
134+
def add(a, b), do: a + b
135+
end
136+
137+
However, keep in mind `@moduledoc false` or `@doc false` do not make a function private. The function above can still be invoked as `MyApp.Sample.add(1, 2)`. Not only that, if `MyApp.Sample` is imported, the `add/2` function will also be imported into the caller. For those reasons, be cautious when adding `@doc false` to functions, instead use one of these two options:
131138

132139
* Move the undocumented function to a module with `@moduledoc false`, like `MyApp.Hidden`, ensuring the function won't be accidentally exposed or imported. Remember you can use `@moduledoc false` to hide a whole module and still document each function with `@doc`. Tools will still ignore the module.
133140

134-
* Start the function name with one or two underscores, for example, `__add__/2`, and add `@doc false`. The compiler does not import functions with leading underscores and they hint to anyone reading the code of their intended private usage.
141+
* Start the function name with one or two underscores, for example, `__add__/2`. Functions starting with underscore are autoamtically treated as hidden, although you can also be explicit and add `@doc false`. The compiler does not import functions with leading underscores and they hint to anyone reading the code of their intended private usage.
135142

136143
## Code.fetch_docs/1
137144

0 commit comments

Comments
 (0)