Baking loves static types

Working in languages like JavaScript, Python, or Ruby, you get a little tired of your colleagues extolling the speed and efficiency of their statically-typed languages as they’re waiting on their compilers. Hypocrites. And it’s not that you’re opposed to the idea–it’s just that another layer of complexity atop your already-convoluted program hardly seems worth the fuss. Is it really worth the trouble to write your program’s types up front? What’s the upside?

Well, I’m waiting on my compiler. I’ll give it a go.

Let’s make some bread

Imagine that we’re having a potluck, and you’ve signed up to bring a nice, warm load of bread. You’ve always wanted to try making it. What better excuse than feeding your friends?

So you find a sourdough bread recipe. The author has provided two functionally-identical-but-visually-divergent versions–odd, but also rather useful for our conversation.

Here’s the first.

Rustic Loaf

Prepare leaven, set out overnight.

Mix 1½c leaven, 1½ tsp salt, and 1c water. Continue to stir and gradually add 1½c of bread flour and 1c of whole wheat flour until sticky arms of dough begin clinging to the edges of the bowl. Set aside to rest for a few minutes, then perform a first turn. Over the next two hours, turn on the half-hour as time allows.

Once the dough has doubled in bulk, fold into a rough boule, cover, and set aside to rest. Repeat fold on the hour over the next two hours.

Once the dough has risen by half, preheat the oven to 450° with a dutch oven inside. Reshape loaf and allow to rest until the oven reaches temperature.

Slash bread and bake, covered, in dutch oven for 40m. Uncover and cook for an additional 10-15m, or until crust is golden brown.

Try “executing” the recipe, and don’t cheat! Just start from the top (no peeking ahead) and keep going until you hit a snag.

Take your time. I’m still waiting on that compiler…

Some time later

Hopefully you’re preening over a gorgeous, crunchy-crusted loaf of sourdough bread. But did everything goes as smoothly as it could? Specifically, did you:

  • wait around an extra day for the leaven to activate?
  • need to go to the store to get salt?
  • need to go to the store to get bread flour?
  • need a larger mixing bowl when the first one overflowed with bread flour?
  • need to go to the store to get whole wheat flour?
  • need to wait 20m for the oven to warm up?
  • need to go to the store for a larger baking pan?
  • you get the idea.

If so, I have good news. If we peek at the second version of the exact same recipe, we’ll notice that the ingredients and time investment are clearly called out at the top:

Rustic Loaf

Prep: 15m
Cook: 1h at 450°
Total: 20h

1½ c leaven
1½ tsp salt
1 c water
1½ c bread flour
1 c whole-wheat flour

Prepare leaven, set out overnight.

Mix leaven, salt, and water. Continue to stir and gradually add flour until sticky arms of dough begin clinging to the edges of the bowl. Set aside to rest for a few minutes, then perform a first turn. Over the next two hours, turn on the half-hour as time allows.

Once the dough has doubled in bulk, fold into a rough boule, cover, and set aside to rest. Repeat fold on the hour over the next two hours.

Once the dough has risen by half, preheat the oven to 450° with a dutch oven inside. Reshape loaf and allow to rest until the oven reaches temperature.

Slash bread and bake, covered, in dutch oven for 40m. Uncover and cook for an additional 10-15m, or until crust is golden brown.

This time we can come prepared. We can have the right ingredients on hand, and begin the recipe well ahead of time. We can make the right assumptions about how the recipe will play out: the size of the bowl we’ll need to fit four cups of flour, and (with some experience) the time and temperature needed to cook it to delicious, chewy perfection.

Knowing what we’re in for up front won’t usually make or break a human. If we run out of flour, we can always go to the store and get more. Maybe we arrive a bit late at the party, but there’s usually enough to go on in our big bag of past experiences to hack up an answer and get things back on track.

Computers are a different story. Our runtime may or may not know about stores or how to invoke them. If it doesn’t, an OutOfFlourException may bring dinner plans to an abrupt stop. Where you or I may find it helpful to know what we’re getting into, a computer may need to know. Then, just like us, it can use that knowledge to anticipate failure states and ring the appropriate warning bells before the program even starts.

Which is what that compiler I’m still waiting on is sorting out. It’s almost done.

The big limitation, of course, is that no amount of information up front can explain the recipe itself (at least, not without pinning us up against an awkward, self-referential wall). It can speed up the run; it can anticipate problems downstream; but it can’t tell you what, when, and how the ingredients will need to together. Recipe or not, your bread may not rise. Your program may fail. But like any dedicated baker (or programmer) you’ll of course tip the odds as far as you can.

Hey, it's RJ—thanks for reading! If you enjoyed this post, would you be willing to share it on Twitter, Facebook, or LinkedIn?