Skip to content
mgd.dev

Expecting Bananas

May 09, 2025
2 min read
design thinkingsoftware architecturecode quotesphilosophy

"If a function expects a banana, don't hand it a coconut."

๐ŸŽง Listen to this post (1:10)

Expecting Bananas

When you write a function, you're not simply saying "do this".

You're implicitly saying "I expect this to be true."

In the same way that a monkey expecting bananas will be disappointed by a coconut, a function expecting strings will be disappointed by a number.

Monkey Expectations vs Reality

Here's one way to express that expectation in TypeScript:

typescript
1function chimp(food: any) {
2  if (food !== "banana") {
3    throw new Feces("๐Ÿ’ EXPECTED: ๐ŸŒ  GOT: " + food + " ๐Ÿ’ฉ");
4  }
5  return "๐Ÿ˜‹";
6}
7
8class Feces extends Error {
9  constructor(message: string) {
10    super(message);
11    this.name = "๐Ÿ’ฉ UnexpectedFoodException ๐Ÿ’ฉ";
12  }
13}
14
15chimp("banana");  // "๐Ÿ˜‹"
16chimp("coconut"); // ๐Ÿ’ฉ UnexpectedFoodException ๐Ÿ’ฉ: ๐Ÿ’ EXPECTED: ๐ŸŒ  GOT: coconut ๐Ÿ’ฉ
17

The beauty of explicit expectations is that when they're violated, you get clear, actionable feedback instead of mysterious bugs downstream.