Skip to content

Commit 90af53c

Browse files
author
José Valim
committed
Merge pull request #1830 from jwarwick/behaviour_docs
Doc updates for Application.Behaviour and Behaviour
2 parents a7e63ae + 2566dd7 commit 90af53c

File tree

2 files changed

+32
-31
lines changed

2 files changed

+32
-31
lines changed

lib/elixir/lib/application/behaviour.ex

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,40 @@
11
defmodule Application.Behaviour do
22
@moduledoc """
3-
This module is a convenience to define application module callbacks.
3+
Default callbacks for applications.
44
55
In Erlang/OTP, an application is a component that can be started
6-
and stopped as a unit, and which can be re-used in other systems
7-
as well.
6+
and stopped as a unit, and which can be reused in other systems.
87
9-
The first step to achieve this is to define an application specification.
8+
The first step in creating an application is to define an application specification.
109
For example, if your application is named `:my_app`, an app specification
1110
should exist at `ebin/my_app.app`. This file is usually defined by
1211
build tools like Mix.
1312
14-
Then, with the app specification in hands, we must also define an
15-
application module callback that controls how to start and stop
16-
such applications. This module is about defining such callbacks.
13+
With the app specification in hand, we must define
14+
application module callbacks that control how to start and stop
15+
instances of the application. This module is about defining such callbacks.
1716
18-
There are two callbacks required to be implemented:
17+
There are two callbacks which must be implemented:
1918
20-
1. `start(type, args)` - It must return `{ :ok, pid }` or
19+
1. `start(type, args)` - must return `{ :ok, pid }` or
2120
`{ :ok, pid, state }`, where `pid` is the process identifier
22-
of the supervisor tree root;
21+
of the supervisor tree root and `state` is application defined
22+
state information;
2323
24-
2. `stop(state)` receives the state returned by `start` and should
25-
do any necessary cleaning up. Notice that shutting down the supervisor
24+
2. `stop(state)` - receives the `state` returned by `start` and should
25+
do any necessary clean up. Notice that shutting down the supervisor
2626
is automatically handled by the VM;
2727
28-
When using this module, it simply tags the module behaviour as
29-
`:application` and defines a default `stop/1` callback. The `start/2`
30-
still needs to be defined by the user.
28+
When using this module, it tags the module behaviour as
29+
`:application` and provides a default `stop/1` callback. The `start/2` callback
30+
still needs to be implemented by the user.
3131
3232
You can learn more about the `:application` module, the application
33-
specification and the application module callbacks below:
33+
specification and the application module callbacks from these sources:
3434
35-
http://www.erlang.org/doc/man/application.html
36-
http://www.erlang.org/doc/design_principles/applications.html
37-
http://learnyousomeerlang.com/building-otp-applications
35+
* http://www.erlang.org/doc/man/application.html
36+
* http://www.erlang.org/doc/design_principles/applications.html
37+
* http://learnyousomeerlang.com/building-otp-applications
3838
3939
## Example
4040
@@ -102,4 +102,4 @@ defmodule Application.Behaviour do
102102
defoverridable [stop: 1]
103103
end
104104
end
105-
end
105+
end

lib/elixir/lib/behaviour.ex

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
defmodule Behaviour do
22
@moduledoc """
3-
A convenience module for defining behaviours.
3+
Utilities for defining behaviour intefaces.
4+
45
Behaviours can be referenced by other modules
5-
in order to ensure they implement the proper
6-
callbacks.
6+
to ensure they implement required callbacks.
77
88
For example, you can specify the `URI.Parser`
9-
behaviour as follow:
9+
behaviour as follows:
1010
1111
defmodule URI.Parser do
1212
use Behaviour
@@ -18,32 +18,33 @@ defmodule Behaviour do
1818
defcallback default_port() :: integer
1919
end
2020
21-
And then a specific module may use it as:
21+
And then a module may use it as:
2222
2323
defmodule URI.HTTP do
2424
@behaviour URI.Parser
2525
def default_port(), do: 80
2626
def parse(info), do: info
2727
end
2828
29-
In case the behaviour changes or URI.HTTP does
29+
If the behaviour changes or `URI.HTTP` does
3030
not implement one of the callbacks, a warning
3131
will be raised.
3232
3333
## Implementation
3434
35-
Behaviours since Erlang R15 must be defined via
35+
Since Erlang R15, behaviours must be defined via
3636
`@callback` attributes. `defcallback` is a simple
3737
mechanism that defines the `@callback` attribute
38-
according to the type specification and also allows
39-
docs and defines a custom function signature.
38+
according to the given type specification. `defcallback` allows
39+
documentsion to be created for the callback and defines
40+
a custom function signature.
4041
4142
The callbacks and their documentation can be retrieved
4243
via the `__behaviour__` callback function.
4344
"""
4445

4546
@doc """
46-
Defines a callback according to the given type specification.
47+
Define a function callback according to the given type specification.
4748
"""
4849
defmacro defcallback({ :::, _, [fun, return] }) do
4950
do_defcallback(fun, return, __CALLER__)
@@ -54,7 +55,7 @@ defmodule Behaviour do
5455
end
5556

5657
@doc """
57-
Defines a macro callback according to the given type specification.
58+
Define a macro callback according to the given type specification.
5859
"""
5960
defmacro defmacrocallback({ :::, _, [fun, return] }) do
6061
do_defmacrocallback(fun, return, __CALLER__)

0 commit comments

Comments
 (0)