Skip to content

Commit d4756f2

Browse files
committed
Polish the "Writing Documentation" page in the documentation
[ci skip]
1 parent b9e2197 commit d4756f2

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

lib/elixir/pages/Writing Documentation.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ Elixir treats documentation as a first-class citizen. This means documentation s
44

55
## Markdown
66

7-
Elixir documentation is written using Markdown. There are plenty of guides on Markdown online, we recommend the ones available at GitHub as a getting started point:
7+
Elixir documentation is written using Markdown. There are plenty of guides on Markdown online, we recommend the ones available on GitHub as a getting started point:
88

9-
* https://help.github.com/articles/markdown-basics/
10-
* https://help.github.com/articles/github-flavored-markdown/
9+
* [https://help.github.com/articles/markdown-basics/](https://help.github.com/articles/markdown-basics/)
10+
* [https://help.github.com/articles/markdown-basics/](https://help.github.com/articles/github-flavored-markdown/)
1111

1212
## Module Attributes
1313

@@ -34,7 +34,7 @@ Documentation in Elixir is usually attached to module attributes. Let's see an e
3434
end
3535
end
3636

37-
The `@moduledoc` attribute is used to add documentation to the module. `@doc` is used before a function to provide documentation for it. Besides the attributes above, `@typedoc` can also be used to attach documentation to types defined as part of typespecs.
37+
The `@moduledoc` attribute is used to add documentation to the module. `@doc` is used before a function to provide documentation for the function that follows. Besides the attributes above, `@typedoc` can also be used to attach documentation to types defined as part of typespecs.
3838

3939
## Function Arguments
4040

@@ -55,11 +55,11 @@ The compiler will infer this argument as `map`. Sometimes the inference will be
5555

5656
When writing documentation:
5757

58-
* Keep the first paragraph of the documentation concise and simple, typically one-line. Tools like [ExDoc](https://github.com/elixir-lang/ex_doc/) use the first line to generate a summary.
58+
* Keep the first paragraph of the documentation concise and simple, typically one line. Tools like [ExDoc](https://github.com/elixir-lang/ex_doc/) use the first line to generate a summary.
5959

6060
* Reference modules by their full name.
6161

62-
Markdown uses backticks (`` ` ``) to quote code. Elixir builds on top of that to automatically generate links when module or function names are referenced. For this reason, always use full module names. If you have a module called `MyApp.Hello`, always reference it as `` `MyApp.Hello` `` and never as `` `Hello` ``.
62+
Markdown uses backticks (`` ` ``) to quote code. Elixir builds on top of that to automatically generate links when module or function names are referenced. For this reason, always use full module names. If you have a module called `MyApp.Hello`, always reference it as `` `MyApp.Hello` `` and never as `` `Hello` ``.
6363

6464
* Reference functions by name and arity if they are local, as in `` `world/1` ``, or by module, name and arity if pointing to an external module: `` `MyApp.Hello.world/1` ``.
6565

@@ -73,21 +73,21 @@ When writing documentation:
7373

7474
## Doctests
7575

76-
We recommend that developers include examples in their documentation, often under their own `## Examples` heading. To ensure examples do not get out of date, Elixir's test framework (ExUnit) provides a feature called doctests that allows developers to test the examples in their documentation. Doctests work by parsing out code samples starting with `iex>` from the documentation. You can read more about it at `ExUnit.DocTest`.
76+
We recommend that developers include examples in their documentation, often under their own `## Examples` heading. To ensure examples do not get out of date, Elixir's test framework (ExUnit) provides a feature called doctests that allows developers to test the examples in their documentation. Doctests work by parsing out code samples starting with `iex>` from the documentation. You can read more about it in the documentation for `ExUnit.DocTest`.
7777

78-
Notice doctests have limitations. When you cannot doctest a function, because it relies on state or side-effects, we recommend developers include examples directly without the `iex>` prompt.
78+
Note that doctests have limitations. When you cannot doctest a function, because it relies on state or side-effects, we recommend developers include examples directly without the `iex>` prompt.
7979

80-
## Documentation != Comments
80+
## Documentation is not Comments
8181

8282
Elixir treats documentation and code comments as different concepts. Documentation is for users of your Application Programming Interface (API), be it your co-worker or your future self. Modules and functions must always be documented if they are part of your API.
8383

84-
Code comments are for developers reading the code. They are useful to mark improvements, leave notes for developers reading the code (for example, you decided not to call a function due to a bug in a library) and so forth.
84+
Code comments are for developers reading the code. They are useful to mark improvements, leave notes for developers reading the code (for example, you decided not to call a function due to a bug in a library), and so on.
8585

8686
In other words: documentation is required, code comments are optional.
8787

8888
## Hiding Internal Modules and Functions
8989

90-
Besides the modules and functions libraries provide as part of their public interface, libraries may also implement important functionality that is not part of their API. While these modules and functions can be accessed, they are meant to be internal to the library and thus should not have documentation for end users.
90+
Besides the modules and functions that libraries provide as part of their public interface, libraries may also implement important functionality that is not part of their API. While these modules and functions can be accessed, they are meant to be internal to the library and thus should not have documentation for end users.
9191

9292
Luckily, Elixir allows developers to hide modules and functions from the documentation. For example, one common practice for documenting internal behaviour is to set the `@moduledoc` attribute to `false` while documenting each function:
9393

@@ -102,7 +102,7 @@ Luckily, Elixir allows developers to hide modules and functions from the documen
102102
end
103103
end
104104

105-
Similarly, developers can add `@doc false` to functions they do not want to be publicly exposed:
105+
Similarly, developers can add `@doc false` to functions they do not want to show up in the documentation:
106106

107107
defmodule MyApp.Sample do
108108
@doc false
@@ -113,14 +113,14 @@ However, keep in mind that adding `@doc false` does not make the function privat
113113

114114
* 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.
115115

116-
* 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.
116+
* 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 suggest to anyone reading the code that they're meant to be used privately.
117117

118118
## Documenting Private Functions
119119

120120
Elixir warns if a private function has a `@doc` attribute and discards its content, because `@doc` is intended to be used only for your public interface.
121121

122122
Private functions may still need internal documentation for maintainers, though. That can be accomplished with code comments.
123123

124-
## Code.get_docs/2
124+
## Retrieving Documentation
125125

126126
Elixir stores documentation inside pre-defined chunks in the bytecode. It can be accessed from Elixir by using the `Code.get_docs/2` function. This also means documentation is only accessed when required and not when modules are loaded by the Virtual Machine. The only downside is that modules defined in-memory, like the ones defined in IEx, cannot have their documentation accessed as they do not have their bytecode written to disk.

0 commit comments

Comments
 (0)