About (about v0.0.7)
Adds documentation to iex. Provides About topics.
These functions are not intended to be used at runtime, they only exist to provide documention.
Topics include:
- regex
- sigils
Link to this section Summary
Functions
About provides help topics for things that are not library functions.
A resuable subsystem. For example logging is an application that would be used in many packages.
Function parameters may be given defaults.
The official formatting is the result of mix format FILENAME
Explains the About library.
The Elixir/Erlang philosophy is unless you can handle an error "let it crash".
Files, Functions and Variables are named in snake_case.
Modules are named in PascalCase
Functions that return only booleans (predicates) are named xxx?
Phoenix is a commonly used web framwork. The following steps help setup
The pipeline operator |>
is used between two functions and
uses the output from the first as the input to the second.
These can be chained.
You can declare a function to be private by using defp.
Building block of the system. These can be monitored, linked and restarted. Much smaller than operating system equivalents. You can have 100K on a typical machine.
You can use ctrl-C twice.
Regex
A defined set of applications intended to be deployed together. This is the top level system.
Sigils are a means to turn form strings with special properties
You can match on strings in parameters
Used for lifecycle management of processes and other supervisors. Supervision trees provide application resiliance.
Useful websites
Link to this section Functions
about_About()
About provides help topics for things that are not library functions.
iex > exports About
for a list of topics.
application()
A resuable subsystem. For example logging is an application that would be used in many packages.
Systems are deployed in Releases.
branching()
defaults()
Function parameters may be given defaults.
def foo(options \ %{})
formatting_code()
The official formatting is the result of mix format FILENAME
help()
Explains the About library.
Usage:
iex > About.help
let_it_crash()
The Elixir/Erlang philosophy is unless you can handle an error "let it crash".
Don’t code defensively - Joe Armstrong
(http://erlang.org/download/armstrong_thesis_2003.pdf))
Adding error handling that you can't recover from for something unexpected will mask bugs. Let it crash, log the error and let a supervisor restart the process in a clean state.
Elixir applications are usually constructed with supervisors (this is beyond the scope of these exercises):
https://elixir-lang.org/getting-started/mix-otp/supervisor-and-application.html
naming_conventions()
Files, Functions and Variables are named in snake_case.
Modules are named in PascalCase
Functions that return only booleans (predicates) are named xxx?
The is_
prefix is usually reserved for guard clauses (or for functions that
may be used in a guard).
'Inner' helper functions are normally private (defp) and named do_xxx where xxx is the 'outer' function.
phoneix_setup()
Phoenix is a commonly used web framwork. The following steps help setup
mix local.hex mix archive.install hex phx_new docker run -d -e POSTGRES_PASSWORD=postgres -p 5432:5432 postgres:11 mix phx.new [PROJECT NAME]
Follow the instructions from there.
pipeline()
The pipeline operator |>
is used between two functions and
uses the output from the first as the input to the second.
These can be chained.
iex> [3,2,1] |> Enum.sort() |> Enum.take(2) [1, 2]
private_functions()
You can declare a function to be private by using defp.
This can only be used from within the module that it is declared.
If code is not needed outside the module then declare it defp. This will help the compiler spot unused code and makes finding typos easier.
process()
Building block of the system. These can be monitored, linked and restarted. Much smaller than operating system equivalents. You can have 100K on a typical machine.
quit_iex()
You can use ctrl-C twice.
You can use ctrl- once
regex()
Regex:
Regex in Elixir can be specific using the ~r sigil:
~r/Aa/
You can enable unicode support with: ~r/aPattern/u
release()
A defined set of applications intended to be deployed together. This is the top level system.
sigils()
Sigils are a means to turn form strings with special properties
~r defines a Regex
~s Strings - generates strings (useful for embedded quotes)
~c Charlists
~w Wordlists ~w(first second third) This has three trailing modifiers that change the type:
a - atom s - string c - charlist
string_matching()
You can match on strings in parameters:
def foo(line = "*" <> _), do: ...
This will allow you to match on strings that start with *, yet have the entire string.
supervisor()
Used for lifecycle management of processes and other supervisors. Supervision trees provide application resiliance.
websites()
Useful websites:
- The language: https://elixir-lang.org/
- The forum: https://elixirforum.com/
- The school: https://elixirschool.com/en/
- The package mangement: https://hex.pm/
- Documentation: https://hexdocs.pm/
- The mentored exercism: https://exercism.io/my/tracks/elixir