We want a banana cake. We are willing to gather the ingredients, and then think (!) and write (!!) to bring that banana cake about.
We could choose to write a recipe: an ordered list of specific actions. Recipes are procedural:
- measure out 100 g of butter, 250 g flour, 100 g sugar, 250 cm 3 water, 20 g baking soda, 10 g baking powder
- take out 3 ripe bananas and 2 large eggs
- using a whisk, beat the eggs
- mash the bananas with a fork
- melt the butter using a steamer over low fire
- add first the wet ingredients, then the dry ingredients, to the Panasonic PM106 bread-maker
- use the “#19 quick bread” feature
We call this “do this, do that” the imperative style.
We could, instead, write a work order / wish-list / specification. This (mostly unordered) list is aspirational:
Banana Bread:
- sweetness: not-too-sweet
- gluten-free: true
- vegan: false
- nuts: [lightly toasted walnut]
- extras: dulce de leche1
We call this the declarative style.
With Ash Framework, you write work orders and, magically, the work gets done.
If you are actually 5 years old, magic sounds great. I am guessing you just pretend to be five: the word Magic and those emojis brings you bitter memories, of being disillusioned, or of javascript frameworks. Let’s go a little deeper.
Under the imperative recipe paradigm, instructions are precise. Under the control hides brittleness. If the kitchen doesn’t have a bread-maker, or don’t have the right model of the bread-maker, all bets are off. If we want gluten-free banana bread, we will add a nice foot-note “Use Bob Red Mill’s 1-for-1 Gluten Free flour, or a 4:5:1 mix of […]”. Over time, the 7 steps recipe becomes an entangled mess of foot-notes, many conflicting with one another. Dad and mom argue if they should refactor the recipe.
With the declarative work order paradigm, nothing was ever precise. The outcome depends on:
- the craftsmanship of the baker taking the work order,
- your understanding of what the baker’s limits are, and
- whether the baker is too proud to let you into the kitchen.
Coming back to code-land, Ash-the-Baker has some hard-won skills and despite that, stays pretty humble.
- Don’t have a database? Just substitute
Ash.DataLayer.ETS
. OrAshCsv
like in the upcoming tutorial. Ash is aware of whether you have a database, and thus when to construct SQL queries and when to do the queries in Elixir. (Why use a steamer when you have a microwave?)- Gluten-free? Vegan? Ash accommodates most standard requests out of the box.
- Want your finished banana bread in GraphQL or JSON shapes? No problem.
- You want to add some some Chili Pepper Infused Garlic Jam™ per your family tradition? Ash lets you in the kitchen to do that part. (Plenty of escape hatches.)
Keep this analogy of recipe vs. work order in mind as we work through Professeur Bunsen’s request.
continue reading on jon.hk
⚠️ This post links to an external website. ⚠️
If this post was enjoyable or useful for you, please share it! If you have comments, questions, or feedback, you can email my personal email. To get new posts, subscribe use the RSS feed.