Edge-Free Programming, by Michael Feathers

Reading Time: 4 minutes

I read books about programming. I usually donate them when I’m finished, but a few books remain on my shelf for immediate reference. These books help me improve my code on any stack and for any machine. I have turned to Michael Feathers’s Working Effectively with Legacy Code while writing .Net servers, Java servers, native Android, native iOS, Javascript frontends, Go command line tools, and (most recently) a Rails database app. Obviously, I’m a fan of the book.

Michael is now in the early stages of writing another book called Edge Free Programming, but you don’t have to wait for the publication date to find out what he is talking about because he did this handy talk:

I’m not saying the talk replaces the book, people. What I’m saying is that I think you, as a programmer, would benefit from this talk. If you’re a busy programmer, you’ll be thrilled to know that it’s 1.5-speed approved.

I have written you a watcher’s guide to ease your consumption process even more.

  1. (Minutes 0:00-5:28): Edges, for the purpose of this talk, represent pieces of functionality that interrupt the flow of your program. Examples: logging, exceptions.
  2. (Minutes 5:28-18:05): Michael uses an example to walk through his proposed approach to edges while building a program from scratch. This link will take you right to 5:28. Here’s his proposed approach (devoid of the example for context, which is why I highly recommend watching this bit yourself):
    1. Write the happy path first as if the edges do not exist. (From experience I will add that this is a psychologically helpful way to make progress. As you think of edge cases, write them on a post-it and come back later rather than getting distracted right now).
      1. Additional note for my Android and iOS people: the example is Ruby. ‘puts x’ = System.out.print(x); (Java) or print(x) (Kotlin, Swift).
      2. He talks about Arithmetic encoding for a little bit. You don’t need it to understand his overall approach, but if you want to understand it, Googling it won’t help you because your top results will be a different thing than what he is talking about.Michael is multiplying an array containing a string by an integer to make a set of strings that, taken together, will draw a picture.
    2. Identify all the edges that have to do with invalid input to your program. Handle these first, before you do any manipulation of the inputs.Michael likens this concept to a soft candy surrounded by a hard shell. I have also heard this concept likened to the customs process in international travel.


  3. (Minutes 18:05-35:30):Michael then goes into some of the mechanisms you can do to handle the edges, like the Null Object pattern and a monadic error pattern.
    1. A helpful cross-reference on this part is Chapter 4 of Confident Ruby by Avdi Grimm. Avdi starts with how to identify inputs, which Michael’s example doesn’t cover because he is writing a command line program that gets all its inputs from ARGV[x]. Your inputs as an app dev are probably more complicated than that.
    2. On the monadic error pattern: Michael mentions that he has to write his own implementation of monads because Ruby doesn’t provide one. If you’re not writing Ruby, your language might have support for this, so do check for that before you hand-code monads. For more on monads in general, I like this burrito explanation by Chris Done.

If you Can’t Get Enough

If you loved this talk or Michael’s book, I also recommend his blog.

If you Still Can’t Get Enough, Check Out:

Diagramming Data (three part series on handling complex inputs at a high level)

A Reading Guide to Test Driven Development by Kent Beck


One comment

  1. Lots of aspects of the linked video remind me of Jon Bentley’s classic ‘Programming Pearls’ – specifically, getting down to Asking The Right Question™ before writing anything

    It’s humbling how many times engineer[-types] start *doing* before they have a plan!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.