Elixir design and refactoring books

I’m coming from Ruby and Rails. I have read some Elixir and Phoenix books. They shed a lot of light about building applications in Elixir. What I’m not clear on is what patterns are promoted for growing Elixir applications. Little things are promoted, as far as I can tell, but it doesn’t get too specific. I’m a heavy book consumer and in Ruby the books that I view as extremely well thought out and thorough include:

Rails antipatterns
99 Bottles of OOP
Confident Ruby
Practical Object Oriented Design using Ruby (POODR)
Refactoring - Ruby Edition
Ruby Science
(and the list goes on)

Are there any books in the Elixir world that cover these topics (design, refactoring) as deeply as these books do in Ruby?

Thank you

1 Like

Hello, welcome to the forum.

As I also comes from Ruby/Rails I had the same questions when I started :slight_smile:

But functional programming is not OOP, no object, no classes, and known design patterns doesn’t apply.

It’s just different.

But You might soon see that functional proramming brings You a lot of safety (no mutation) and a different mindset.

Now, when I write Ruby, I try to apply functional paradigm principles :slight_smile:

Here are videos You might enjoy (as I did…)

There is also this recent topic, where some books are recommended…

9 Likes

Thank you!

Thank you so very much!

Further to what Koko has said, if you like Dave’s talk you might also be interested in his course: Elixir for Programmers (PragDave) (Currently on offer for $30!) (have a look at the comments/reviews in the thread). It’s not really about refactoring and such, but you do get a look into how Dave goes about architecting software (at least at the time he recorded the course) :smiley:

2 Likes

I hope You enjoyed presentations, as they were kind of mind blowing for me.

Here is my 2 cents advises…

  • pattern matching is THE thing
  • |> creates beautiful and descriptive transformation pipeline
  • The Enum module is a must
  • Lists are not arrays
  • Polymorphism can be achieved via protocols

And many more that I forget, all of these You can learn on https://elixir-lang.org

The last advise, for Rails developpers, Ecto is not AR, but You can do equal job… (same same, but different) Here is a post about a free resource on Ecto.

FP is just a mean to achieve greater goal, Here is a post from Erlang creator, about Erlang.

Once You reach the syntax barrier, You will see it allows You to have a complete isolation…

In complete isolation, You can have millions of processes working together. Coupled with a faillback mecanism (Supervisor) You can build softwares that are fault tolerant.

Apart from Functional patterns, there are Design Patterns for processes, it’s called OTP.

6 Likes

Thank you. I’ll take a closer look at OTP.

Regarding patterns/refactoring, in OOP there’s the idea of focused objects/little things. This is represented in objects like Services, Policies, Queries, Presenters, Decorators, etc… Are these patterns relevant in the elixir world as well? Doing some Googling doesn’t reveal much.

The beginner examples in both ruby and elixir show much of the examples either in irb/iex or in a Rails/Phoenix controller. This does not scale. In the Rails world I just look up some common patterns and I get a plethora of results. This does not happen with Elixir so I think I don’t know the patterns (and possibly they aren’t even called patterns).

1 Like

In FP it’s the same, You just call those things functions. And You compose those functions to make bigger things.

Presenters, Decorators are from OOP, there is no need because functions are highly composables.

Services, Policies, Queries are probably bounded in a module.

Please note that in Erlang/Elixir we have MFA, You will see this a lot.

It means Module, Function, Arguments :slight_smile:

2 Likes

I took the same way You did, just a bit earlier. As You, I read all the Ruby books You mentionned…

I can remember the depressing feeling of not finding the equivalent of what I learned, all those things Sandi Metz was praising… is it just replaced by MFA?

In Ruby, often You find small objects, used for one function only, that could be parser.parse(), presenter.present()… anything like this. In FP You pass a function.

High order functions are so powerful (something Ruby touch with Lambda) that You don’t need Template, or Strategy patterns.

In Erlang/Elixir, we have some famous Erlangelist… this is one of my favourite talk to understand why this difference is so appealing.

He is the author of Elixir in action, and runs https://www.theerlangelist.com/

3 Likes

Have you read Elixir in Action? Much of the book builds on the same example application of a todo system, with increasing complexity (adding a caching layer, persistency, fault-tolerancy, a web interface, and distribution). When I started out with Elixir I found the way this example evolved over the course of the book a really good guideline for how to evolve a real-world Elixir application.

2 Likes

Now that I’ve read (most of) it, it’s worth noting that the Ecto book also has a chapter on application design (covers pure/impure, Contexts, Umbrellas) while of course Programming Phoenix also covers application design in terms of Contexts - I highly recommend both books :smiley:

Other books not mentioned here that cover app design (that I haven’t read yet) are Functional Web Development with Elixir, OTP, and Phoenix (Pragprog) and Designing Elixir Systems with OTP (Pragprog) and The Elixir Toy Robot (self-published) may also be worth a look :smiley:

2 Likes

Let’s not forget that BEAM languages also enable CP - Concurrent Programming. The core pattern is a behaviour (see also discussion).

Garret Smith had an effort some years ago to capture some Erlang Patterns which are still available in some markdown documents here - the mostly apply to Elixir as well.

3 Likes

In FP it’s the same,

Sorry, I was kind of oversimplifying.

1 Like

Hi,

Just trying to complement what others have already mentioned. I found this book about functional programming very useful for someone with an OO background:

https://pragprog.com/book/cdc-elixir/learn-functional-programming-with-elixir

And, if you really want to know more about design patterns in functional languages, this other one provides examples in Scala and Clojure:

https://pragprog.com/book/mbfpp/functional-programming-patterns-in-scala-and-clojure

However, I think you better off learning the basics of FP and move where your interests take you. You’ll be amazed at how much you can accomplish with just modules and functions.

3 Likes