Posts by José Valim

Mocks and explicit contracts

Our test tools often make it very easy to abuse mocks. This post provides some guidelines on using them properly by relying on explicit contracts.

Working with Ecto associations and embeds

This blog post aims to document how to work with associations in Ecto, covering how to read, insert, update and delete associated models and embeds. At the end, we give a more complex example that uses Ecto associations to build nested forms in Phoenix. Note this article expects basic knowledge Ecto, particularly how repositories, models … »

Elixir in times of microservices

Since microservices have been a common topic lately, there are a lot of questions about how Elixir fits in microservice architectures. On this post, I won’t focus on the merits of microservices, as many have already discussed that to exhaustion. In particular, Martin Fowler’s entry on the topic aligns well with my thoughts and is … »

Introducing reducees

Elixir provides the concept of collections, which may be in-memory data structures, as well as events, I/O resources and more. Those collections are supported by the Enumerable protocol, which is an implementation of an abstraction we call “reducees”. In this article, we will outline the design decisions behind such abstraction, often exploring ideas from Haskell, … »

Build embedded and start permanent in Elixir 1.0.4

Elixir v1.0.4 ships with two new important options for new projects. If you generate a new application with mix new, you will see in your mix.exs: [build_embedded: Mix.env == :prod, start_permanent: Mix.env == :prod] Although those options were originally meant to be in Elixir v1.1, we have decided to bring them into v1.0.4 and do … »

Writing assertive code with Elixir

Functional languages are typically great languages for writing assertive code and Elixir is no exception. In this blog post, I would like to discuss some anti-patterns I have seen in Elixir code and how to rewrite them in a way to make the best of Elixir. Pattern matching Imagine you have a string with format … »