Errors, modules and style
This part is about the shape of a module: the exceptions it raises and catches, the functions it exports, the funs it passes around, and the keyword list that Erlang and OTP use for options.
The style lesson collects the habits that make a module readable: small clauses, immutable data, and an export list that tells the whole story. Higher-order code comes just before it, because a function passed to another function is the clearest example of the style. The part closes with the patterns that decide where an error is handled, and with the documentation a module carries in its own source.
5.1
Exceptions: try and catch
error, throw and exit, try, catch and after, and the class of a failure
Open
5.2
Modules, exports and imports
the module file, the export list, -import and the call into another module
Open
5.3
Funs: anonymous functions
a fun as a value, its closure, and the named fun of OTP 27
Open
5.4
Higher-order functions
a function that takes a function, lists:map and foldl, and a pipeline
Open
5.5
Keyword lists
a list of pairs, the proplists module, and where OTP passes options
Open
5.6
Erlang idioms and clean code
small clauses, immutable data, and the shape of a module the reader trusts
Open
5.7
Error handling patterns
the ok tuple, a throw that aborts a parse, and the boundary that catches a crash
Open
5.8
Documentation and edoc
a doc comment, -doc and -moduledoc, and the HTML edoc writes
Open