Parsing Untrusted Input with Elixir

I’ve spent a lot of time in the past year learning PureScript and it has drastically changed the way I think about programming in general. The biggest change in my thinking is described by the excellent blog post Parse, don’t validate. The most important passage in the post, I think, is this: Consider: what is a parser? Really, a parser is just a function that consumes less-structured input and produces more-structured output. ...

August 23, 2020 · Drew Olson

Parser Combinators in Elixir

Delving into the world of pure functional programming caused me to learn about parser combinators. Upon returning to Elixir, I was excited to see that nimble_parsec is a great example of a parser combinator library for the Elixir ecosystem. Parser combinators can be notoriously confusing when first learned. In this post I’ll provide a gentle introduction to parser combinators via nimble_parsec. What is a Parser Combinator? Have you ever found yourself writing a regular expression to parse input? I know I have. You finally have the syntax correct and then new requirements get added. Suddenly you need to support optional tokens, lists of values and other complicated types of input. When regular expressions start to break down because of complexity, it’s time to reach for a more powerful abstraction. Enter parser combinators. ...

March 14, 2020 · Drew Olson

Elixir's Secret Weapon

I recently began using a new(ish) feature of Elixir that completely transformed the way I build programs. I’m talking about the special form with. It can feel unfamiliar at first, but it is extremely powerful and flexible. This article will explain how with works and how it can be used to make your code more robust to errors. First, though, let’s look at the problem with is trying to solve. ...

May 12, 2017 · Drew Olson

Extensible Design with Protocols

I wrote some code this week that reinforced the power of protocols as a tool for software design. The term “protocol” can mean many things in the world of software. Let me clarify that I’m using protocol to mean the mechanism used by some languages (Elixir, Clojure, etc) to achieve polymorphism. Used properly, protocols allow you the provide users of your code with a set of standard behavior as well as a clear contract for implementing that behavior on standard or custom types. ...

March 19, 2016 · Drew Olson

An Empathetic Functional Language

I’ve been writing Elixir code for over a year. Never have I been more excited about the prospects of the language and its community. The language is young but very promising. Many smart people are getting involved. There’s a hell of a trajectory here for a language that released 1.0 merely 6 months ago. I’ve been wondering what is it specifically about Elixir that has pulled me in and prompted my involvement in the community. In a word, it’s empathy. More specifically, empathy for the user. ...

March 20, 2015 · Drew Olson

Pagination with Phoenix & Ecto

I’ve been working on a web application built in Elixir. I’m using Phoenix as the web framework and Ecto to talk to my database. As the amount of data in the application grew, I needed to paginate some of the views. I wasn’t able to find an existing pagination solution for these tools so I ended up building my own. This post will discuss what I built. Goal Once we’re done, we should be able to paginate any Ecto query using parameters provided by a Phoenix controller action. I’m going to assume you’re familiar with building composable Ecto queries. If you aren’t, read this post. ...

February 20, 2015 · Drew Olson

Composable Queries with Ecto

In my previous post I briefly covered some lessons I’d learned while building a (kind of real) web app in Elixir. Today, I’d like to take an in-depth look at composable queries in Ecto. First, a brief introduction to Ecto. What is Ecto? I think of Ecto as a light-weight ORM. Ecto uses Elixir structs to represent database tables and provides a DSL for building and executing database queries. Because I’m boring, we’re going to use the ages-old “post has many comments” example to demonstrate Ecto’s capabilities. We’ll assume we have the following models. ...

January 23, 2015 · Drew Olson

Building an Elixir Web App

Over the past few months I’ve been building a small internal application at work. I’ve been using Elixir, Ecto and Phoenix and it’s been an absolute blast. I thought it would be useful to put together a “lessons learned” blog post about the techniques I’ve found helpful using these tools to build a database-backed web app. This post is not intended as an introducion to any of the these tools. I assume some knowledge of Elixir, Ecto and Phoenix. ...

January 19, 2015 · Drew Olson