axelson

axelson

Scenic Core Team

8) ElixirConf US 2018 – Growing Applications and Taming Complexity – Aaron Renner

ElixirConf US 2018 – Growing Applications and Taming Complexity – Aaron Renner (@aaronrenner)

Growing an application is hard. We started our app with the best of intentions and promised ourselves we were going to “design it right". However as the app grew, complexity increased, dependencies piled up, and changes that were once small now felt like slogging through mud.

Driven by the need to keep our sanity, we decided to apply ideas from Phoenix’s contexts and Domain Driven Design with the hope that we could put boundaries around the complex parts of our system and keep the code from turning into a tangled rat’s nest. This talk covers many of the lessons we learned along the way, including:

  • How to start tackling complexity by teasing apart the app into multiple layers.
  • How to simplify testing and reduce mental burden by defining contracts between these layers.
  • How to verify contracts using tools like dialyzer, automated tests and mocks.
  • How to document these contracts and use them to guide the application design.

After applying these ideas to our codebase for almost a year, we’re eager to share our experiences and provide strategies you can use to tame complexity in your own applications.

Audience: Intermediate
Topics: phoenix

All talks are available in the ElixirConf US 2018 Talks List or via the elixirconf2018 tag

Most Liked

slashdotdash

slashdotdash

The behaviour/impl module and separate implementation approach is used by the new Elixir Telemetry library.

aaronrenner

aaronrenner

Phoenix Core Team

I know it’s over a year later, but I just posted an in-depth article covering the layering and swapping mechanisms I gave an overview of in this talk.

LostKobrakai

LostKobrakai

I‘ve not had a look at the repo yet, but it‘s probably created by driving the point of the talk all the way to make a point.

On the other hand having clear interfaces is something, which is by no means inherently OO. Interfaces are something your code has even if they‘re not written out somewhere explicitly. At the least you should have it as soon as there are multiple implementations, which can be switched out (and as @josevalim argued when creating Mox, this stands also if a second implementation is just used for testing). This was one point in the talk, that it makes testing easier. But I‘m with you that it‘s quite a bit of ceremony if there‘s only one implementation. It just makes is super clear, which functions are meant to be public interface vs. what is implementation detail. In bigger projects, this might otherwise not be as clear.

Naming errors is imo a good thing like anywhere else in programming, especially for the common cases, which are the ones one has to deal with all the time. It could‘ve been an atom instead of an exception struct, but the latter has the ability to later be enhanced with metadata, while with a plain atom to start with the interface would probably need to change in a backwards incompatible way.

stefanchrobot

stefanchrobot

I really liked the talk! It’s basically advocating the use of the Hexagonal Architecture as a way of tackling growing complexity. Just as any pattern, Hexagonal Architecture has pros and cons. The cons are: more abstractions and indirection. It’s up to the developer to decide if the pros outweigh the cons.

Functional programming does not solve complexity on it’s own. I’m working on a Rails app with a god-class - I can clearly see how one could translate this line-by-line into the Elixir land and cause the same pains. Really, there’s no such thing as an anti-pattern: if you’re hacking a throwaway prototype, then cramming business rules into controllers is fine in my books. I guess most web apps would be fine with the “defaults”, i.e. Ecto leaking into the controllers. But that’s not always the case, especially with growing complexity.

bartlomiej

bartlomiej

I am having mixed feelings about this, the examples in repository (https://github.com/aaronrenner/crowdfundr) even define some very common cases like user entering an email that is already used as an exception (Crowdfundr.EmailAlreadyRegisteredError) and then use that in {:error, exception} tuple.

I am just learning Elixir but I have went through some materials already and I must say this approach looks totally foreign to me. I would even say that it looks like a total oposite of why I turned to Elixir in the first place. The Behaviour/Impl/DefaultImpl thing reminds me too much of the “interface with single implementation” ceremony that used to be common in some OO languages.

What do you think? I would love to hear what others have to say.

Where Next?

Popular in Talks Top

axelson
ElixirConf US 2018 – Building Video Chat with Elixir & Phoenix – Anil Wadghule (@anildigital) In this talk, I will s...
New
blatyo
Looks like videos have started to go up for ElixirConf US 2018. Here’s the playlist of ones available so far. I expect it’ll get updated ...
New
axelson
ElixirConf 2017 - Building an Artificial Pancreas with Elixir and Nerves - by @tmecklem People with Type 1 Diabetes have...
New
axelson
ElixirConf 2017 - Implementing a MQTT client in Elixir - @gausby Elixir has excellent support for binary pat...
New
axelson
ElixirConf 2017 - Embedded Elixir for Monitoring the Built Environment - Christopher Coté At CRT Labs (Natio...
New
JuanjoA
Hi, I don’t know if I have the post in the right place. I put here in case you might be interested, I am not the author, I just found it...
New
axelson
ElixirConf 2017 - Elixir Power Tracing - Gabi Zuniga Tracing is a technique for tracking events during a pro...
New
AstonJ
Keywords: LiveView autocomplete, LiveView search, focus Startups and web developers take note. Phoenix LiveView is the revolutionary fr...
New
axelson
by @jola Can you write a performant string processing scripts in Elixir? This talk attempts to answer that question while incrementally...
New
AstonJ
Day 1 ElixirConf 2017 - Day 1 Keynote - Justin Schneck (Discussion thread) ElixirConf 2017 - My Journey from Go to Elixir - Veronica L...
New

Other popular topics Top

sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
dotdotdotPaul
Okay, I'm having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I'm sure I'...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
sergio
I couldn’t find any guides that worked well with Phoenix 1.6.0 and esbuild. I hope this helps people test the waters and eases you into t...
New
lk-geimfari
What is most correct way to open, read and parse JSON file with poison? For example if we have example.json file in root of some projec...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? https://hexdocs.pm/ecto/Ecto.Repo.h...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
AstonJ
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including. What is Phoenix LiveV...
New

We're in Beta

About us Mission Statement