Where to go next

The course ends with the tools a working Elixir program uses. Three packages cover the work most readers meet next: Phoenix for a web application, Ecto for a database and Livebook for a notebook. All three are Hex packages, and the environment of this course has no Hex and no network, so they are described here and not run.

Phoenix

Phoenix is the web framework of the language. A request arrives, a router matches the path, a controller reads the parameters and a template or a JSON view answers. A channel keeps a WebSocket open for live updates, and a presence tracks who is connected to which topic. Phoenix builds on the OTP application of the previous chapter, and a generated project is a supervision tree with an endpoint and a pubsub server as children.

The entry point of the documentation is the project site; a reader installs the generator with mix archive.install hex phx_new and starts a project with mix phx.new. Both commands download from Hex, which this environment does not allow.

Ecto

Ecto maps a row to a struct and a query to a composable value. A schema names the fields and their types, a changeset checks the values before they reach the database, and a repository runs the query. The typespecs lesson is the same idea for a function; a changeset is the check for the data a user typed.

Ecto needs a driver for the database it talks to, and every driver is another Hex package. A project adds ecto_sql and a driver to its deps list and runs mix ecto.create and mix ecto.migrate; the page describes them and does not run them.

Livebook

Livebook is a notebook for Elixir: cells of code, the output below each cell, and a document that a reader can run from top to bottom. It connects to a running node, so the state of a GenServer is visible a cell at a time, and the notebook is the tool for an experiment that grows into a report. It is a Hex package with an installer, and it is not run here.

The Erlang side

Elixir runs on the Erlang VM, and the Erlang documentation is the reference for the modules the standard library calls: :gen_tcp, :ets, :crypto and the rest. The ETS lesson and the networking lesson used them with the leading colon, which is the whole difference between an Erlang call and an Elixir one.

The course again

A chapter that was hard the first time reads differently after the later ones. The course index lists the chapters and their lessons, and the language hub lists the articles of the site about Elixir. A reader who wants to check a program can copy any of them into a file and run it with elixir, because every lesson keeps its blocks whole.

The descriptions on this page are not commands that were run; the environment of the course has no Hex and no network. Everything the lessons themselves ran was Elixir 1.19.7 on Erlang/OTP 27 (erts 15.2.7.14), on Linux x86_64 in a Docker container.

Questions

A new set of questions in a new order every time. Choose one answer for each, then check.

  1. What is Phoenix?

    Answer

    The web framework of Elixir

    Phoenix handles requests, routes, channels and the endpoint of a web application.

  2. What does Ecto map a database row to?

    Answer

    A struct with a schema and a changeset

    An Ecto schema turns a row into a struct, and a changeset checks the values.

  3. What is Livebook?

    Answer

    A notebook for Elixir that runs cells against a node

    Livebook is the notebook environment; it is not part of the language.

  4. Why are Phoenix, Ecto and Livebook described and not run on this page?

    Answer

    They are Hex packages and this environment has no Hex or network

    The course runs only Elixir and OTP; a package outside them is described.

  5. Which command installs the Phoenix project generator?

    Answer

    mix archive.install hex phx_new

    The generator is installed as a Mix archive from Hex.

  6. What does a changeset do in Ecto?

    Answer

    Checks the values before they reach the database

    A changeset carries the changes and the validation errors.

  7. Where is the documentation of :gen_tcp and :ets?

    Answer

    In the Erlang documentation

    The modules are Erlang modules; the leading colon is the only Elixir difference.

  8. Why does a later reading of chapter 3 make more sense after chapter 9?

    Answer

    The later chapters show the processes and OTP the functions rely on

    The course builds ideas in order; the later chapters explain the earlier examples.

  9. Which page lists the chapters and their lessons?

    Answer

    The course index at /dev/elixir/course/

    The course index is the hub of the chapters and the tree of lessons.

  10. What can a reader do with any program block of the course?

    Answer

    Copy it into a file and run it with elixir, because the blocks are whole programs

    The lessons keep whole programs whose output was pasted from a real run.

Автор статьи: Arthur Isaev

Изображение баннера