Programmer humour
Tags: humour, humor, recipe, rounding
Published: 2023-11-21 16:01:16

---
title: Programmer humour
published: true
description: A programmer explains why their joke is funny and no-one is remotely amused
tags: Humour, Humor, Recipe, Rounding
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1j8am3ahmike3qu32org.jpg
# Use a ratio of 100:42 for best results.
# published_at: 2023-02-22 12:22 +0000
---
<small>Image by [David McPictures](https://www.pexels.com/photo/frog-with-big-eyes-sitting-on-wooden-floor-4246400/)</small>

The origin of the quote about analysing humour and frogs dying can be traced back to 1941. It's an appropriately arid paragraph by [Katharine S. White and her partner](https://quoteinvestigator.com/2014/10/14/frog/):

> Analysts have had their go at humo[u]r, and I have read some of this interpretative literature, but without being greatly instructed. Humo[u]r can be dissected, as a frog can, but the thing dies in the process and the innards are discouraging to any but the purely scientific mind.

I'd like to describe a programming joke I made to you. No one, most of all me, anticipates this will be amusing. I hope this article will be like lifting a rock and watching the various insects scuttle about, unaccustomed to the sunlight and noise. You might briefly enjoy the spectacle, before slamming the rock down again, allowing those disgusting creatures to live out their strange lives in peace.

(Just to be clear, I'm one of the beetles, in this metaphor)

## The power of ignorance

A few years ago, I was working in a start-up where (in the memorable words of one of the founders) my job was to <q>make my daft ideas seem possible</q>. At that particular time, his focus had shifted to producing a website which would feature a series of recipes.

I started researching recipe sites and, despite it being a mature field, instantly felt the unearned confidence that I could do better than those who had been working in the field for decades[^1].

[^1]: Recipe sites are interesting for several reasons. Recipes are not recognised by copyright law so this is why recipe sites are so famous for waffling on (no pun intended) about the lives of the bloggers before getting to the useful information - *that* introduction text *can* be copyrighted, so if someone hoovered up all the text on the page, they would be culpable of stealing content. The irony of all this is that [Google supports a certain kind of markup which makes it trivial to steal all of your recipe data](https://developers.google.com/search/docs/appearance/structured-data/recipe). Why would anyone use this? Because doing so *might* increase your search engine results.

I loved this aspect of my old job - barging into a mature field and throwing together a prototype over a couple of days which looked (if you squinted slightly) like a proper product.

## Recipes are a mathematical problem

Coming at this field with a programmer's brain, two things struck me:

1. Recipes seemed pretty inflexible when it came to the number of people served
2. Recipes seemed to be in either Imperial, Metric or Cups (whatever that means)

Both these problems seemed (from my naive perspective) mathematical in nature. I set about making an interface which would allow users to change the number of portions and the units of measurement to their heart's content.

### Cooking is an art, baking is science

There's a lot of banter in the memosphere about cooking - measuring garlic with your heart, not your scales etc. This suggests that many recipes have a wide margin of error which can be abused to serve personal taste.

Notably, this is *not* the case for baking, where a recipe can be replicated perfectly but then fail to rise due to a difference between the atmospheric pressure in the original author's kitchen and the kitchen of the end user. This suggested that the accuracy of the converted measurements was very important.

I realised that when converting the recipes between different portion sizes and units of measurement, the values I'd end up with would have a lot of decimal places. These decimal places must be protected at all costs!

## In defence of Imperialism

In some circles on the Internet, it's fashionable to bash the Imperial form of measurement. Perhaps you've seen this world map of the countries which use Imperial units of measurement in your travels:

<figure>
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i58ju3vo5wsza3c6p7xc.png)
<figcaption>From the article <a href="https://www.zmescience.com/other/map-of-countries-officially-not-using-the-metric-system/" target="_blank">This map shows the countries officially not using the metric system</a></figcaption>
</figure>

Or you've seen this diagram, like some terrible inscription used to summon a demon:

<figure>
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mam26r2z0z038ijy9dcd.png)
<figcaption>The earliest version of this image I could find was on <a href="https://imgur.com/YA4Mskz" target="_blank">Imgur</a>.</figcaption>
</figure>

But that diagram above hints at the reasoning behind the Imperial and cups systems of measurement - it's designed to work on a human scale. Imperial and cups are designed to be split into smaller amounts easily. In the terrifying diagram above, you can see 12 and 16 occur frequently. 12 has four factors: 2, 3, 4 and 6. 16 has three: 2, 4 and 8 (I'm ignoring 1 and 16 here, as neither is useful for my use case).

Ten has two useful factors: 2 and 5.

This means it tends to be easier for a human to break an Imperial recipe into smaller bits than it is to break up a metric recipe.

Obviously, things get a little more complicated when you need to do stuff like deliver a rocket to the moon or a missile into a bunker, but that's a little outside the scope of the problem I was trying to solve, luckily.

## Some vulgar conversation

So I knew I'd end up with some ugly numbers like 1.2334325 after my conversion and I wanted to round these into something friendlier. And what could be friendlier than fractions?

HTML (that ancient language which is still used to this day to render most stuff you see on the web) can't display *all* the fractions. But it can do the following:

¼, ½, ¾, ⅐, ⅑, ⅒, ⅓, ⅔, ⅕, ⅖, ⅗, ⅘, ⅙, ⅚, ⅛, ⅜, ⅝, ⅞ 

## Climb the tree

What my code needed to do after converting a value was to output it using largest to smallest units. So for example:

> Take 3 gallons, 2 pints, 1 cup, 6 tablespoons and 1 teaspoon of milk and empty this into a mixing bowl.

For each conversion, the remainder would be passed on to the next step in the chain, where it would be applied to that unit.

Once I ran out of units, I'd break out the fractions.

Now these fractions worked well if the ingredient being converted was something small, like bicarbonate of soda. It *sort* of makes sense to add ⅑ of a teaspoon of bicarbonate of soda to a cookie recipe originally intended to feed a family of five, which you're making just for yourself. But of course, these fractions were just as likely to turn up in a recipe for pancake batter which you are upscaling to industrial quantities. For example:

> Take 1 stone, 5 pounds, 7oz and ⅜ of a teaspoon of plain flour and put it in a bowl

And I found this idea funny, so naturally, I left it in.

The final product hasn't (yet) reached the market so there's no danger of you stumbling across a site which suggests you add 3 oz and ⅞ of a tea spoon of tomato purée to your spaghetti bolognese yet. But if you ever do stumble upon such malicious compliance, I hope it makes you smile.