Programming Elixir Chapter 13 Notes


Organizing a Project

Spent a lot of time Googling in order to complete exercise #4. Wrapping my head around piping and enumeration. Testing helps. Short snippets in LiveBook helps. Practiced documenting.

  1. mix new did not create the ./config directory.

  2. elem accesses a tuple by index.

  3. Elixir builtins

  4. Erlang documentation Application Group sidebar.

  5. Elixir hex

  6. Version control the mix.lock for applications. Review when building a public library.

  7. Mix.Config is deprecated. Use Config

  8. The configuration sets the minimal log level compiled into the application. Code for lower-levels is not even compiled into the application. For example, setting it at :info means you cannot log :debug.

    Set the compile-time logging in issues/config/config.exs:

    config :logger,
       compile_time_purge_level: :info

    Already outdated, use:

    config :logger,
      compile_time_purge_matching: [
        [lower_level_than: :info]
      ]

  9. The string passed to the log function is always evaluated, even if it is never logged.

  10. Use the function variant when expensive information may not be logged. For example:

    Logger.debug fn -> "#{expensive(value)}"
  11. The documentation to add ex_doc and earmark to the mix.exs development-only and non-runtime flags:

    {:ex_doc, "~> 0.27", only: :dev, runtime: false},
    {:earmark, "~> 1.14", only: :dev, runtime: false},

Exercises

OrganizingAProject-1

Copied the project as recommended.

OrganizingAProject-2

Added dependency as directed.

OrganizingAProject-3

  • Sort of duplicated the code.
  • In playing around with the Poison module I accidentally used encode! instead of parse!, which led me down a rabbit hole of learning how to debug in IEx.

OrganizingAProject-4

My Solution to formatting a table is moderately different from Dave’s. I see where I can improve efficiencies by using map/reduce and doing additional pipelining.

Most importantly, it works!

  • Reduce a list of maps into a map:

    Enum.reduce(list_of_maps, fn x, y ->
      Map.merge(x, y, fn _k, v1, v2 -> v2 ++ v1 end)
    end)

  • Reduce a list of tuples into a map:

    Enum.into(list, %{})

OrganizingAProject-5

Worked through the logging, debugging, and documentation steps. Had made the commandline application earlier.

OrganizingAProject-6

My Solution to the NOAA airport weather lookup.

  • Needed to add :httpoison and :elixir_xml_to_map to applications.

All notes and comments are my own opinion. Follow me at @rgacote@genserver.social