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)
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.

Here's one way to express that expectation in TypeScript:
typescript1function 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.