Code Flow Summary

Congratulations! We covered a lot of ground together! If you took the time to do the exercises then you’ve built up excellent hands-on experience applying these new concepts.

Let’s briefly review what we’ve covered here and stress some take-away points.

What we covered

  • The Pipe Operator |> does a simple job but it enables pipelines which are more elegant and readable.
  • A case statement supports guard clauses and they can be piped into.
  • A Keyword list is a list of tuples. It is frequently used for passing options to a function.
  • The Railway Pattern adds pattern matching clauses and pipelines to create a “happy path” and “failure path”. Works well on functions defined in a module used as a workflow.
  • The “with” statement uses pattern matching to define a “happy path”. It replaces nested case statements and works well for pulling functions together from different parts of the system.
  • Looping in Elixir is done using pattern matching and recursive function calls.
  • Tail recursion is a feature of many functional languages that makes recursive calls able to “loop” forever without a stack overflow.
  • The Enum module has functions that help with processing a list. They include Enum.each/2, Enum.map/2, and Enum.reduce/3.
  • for comprehensions provide a simple way to loop. It is a Swiss Army Knife feature that can do many things. A great tool to have on-hand.
  • Error handling is used less in Elixir than other languages. A raise needs a rescue. A throw needs a catch and an exit is a special type of throw.
  • The if statement exists but is used far less frequently.
  • A nested if is an anti-pattern.
  • The cond statement replaces the if ... else if structures from other languages.

Extra things we picked up on the way

  • IO.inspect/2 is a great debugging and insight tool. It is “pipe friendly” and can be added liberally. Using the label: "My Label" option really helps to identify which inspect call we are looking at.
  • When defining an alias, we can use the alias MyApp.Thing, as: OtherName option to override what it is called.
  • We talked about the Range type (ex: 1..10) and how they can be used for looping.
  • Anonymous functions support multiple clauses. This gives added flexibility when working with Enum list processing functions.
  • Elixir has “truthy” and “falsy” evaluations. A “falsy” value is nil or false. A “truthy” values is anything that is not nil or false.

Lessons learned

Elixir has immutable data, is a “functional language”, uses recursion, doesn’t have “objects”. This can feel very unfamiliar and frankly a little scary. It is exactly these characteristics that are the foundation for the powerful concurrency model and the resilience of Elixir systems. This requires you to learn to do old things in a new way. Even the way you control the flow of your code changes.

Having completed this course, you have experienced for yourself that “you can do this”.

Feeling comfortable with Elixir takes time. You know the techniques, you’ve used the control patterns, and you know when to use them.

Now it is up to you to continue with it. Look for opportunities to use these Code Flow patterns. Don’t be afraid to refactor your code from one pattern into another as you realize something else is a better fit. This is where you really build experience and skill.

You got here on your own. I know you can do this. We did cover a lot and you can return to review anything you need. I think the most important thing you have learned from this is that you know you can do this.

You got this.

Download reference resource

Now that you have completed the course, as a special “thank you”, I want you to have a ready, portable, handy reference as a resource of everything we covered together. This is a PDF download of the course information. It is indexed and searchable so you can easily jump around and find something you want to refer back to.

Comments are closed

This is a static version of the site. Comments are not available.

7 Comments

  1. Ron Male on October 15, 2020 at 5:33 pm

    Both courses are invaluable for learning the foundation of Elixir. Good job and thank you.

    • Mark Ericksen on October 15, 2020 at 9:05 pm

      Thank you! I’m so glad you found them helpful!

  2. henrymori on November 16, 2020 at 5:53 pm

    Excellent resource Mark! Thank you 🙂

    If you came up with a similar course for Ecto (it’s more advanced concepts) then I’d sign up for that in a heartbeat!

    • Mark Ericksen on November 17, 2020 at 5:25 am

      Thanks! I’m glad you enjoyed it!

  3. Ali ELBaitam on November 28, 2020 at 7:55 pm

    Thanks a lot Mark for both courses.

  4. Nathan Azevedo on February 24, 2021 at 5:31 pm

    Really enjoyed the courses, thanks Mark. Any plans for additional courses? OTP/Concurrency, Ecto, or maybe Phoenix?

    • Mark Ericksen on February 25, 2021 at 4:39 am

      Yes, I have been thinking about what could be the next topic. Mostly I’m thinking of how to do it as a small group interactive training.

      I’m glad you found the courses helpful!

Comments are closed on this static version of the site.