Originally published by Robert Beisert at fortcollinsprogram.robert-beisert.com

Patterns for Kids: Clever Elsa

Most of us have at least heard of the Grimm Fairy Tales. The Brothers Grimm travelled through Germany compiling folk tales, which they published into an excellent collection of myths (pattern-conveying stories) that convey simple lessons to us at any age.

Today, we’ll look at the story of Clever Elsa.

———————

Elsa was a serving girl who lived with her wealthy master in his large house. She took care of everything: cooking, cleaning, preparing his clothes, and taking care of any guests the master had. There was just one problem with Elsa: she was extremely lazy, and a bit of a glutton. She hated actually doing her work, and often found clever ways to not do anything she was supposed to.

One day, her master came to her and said that a rich man from the next town would be coming over for dinner. He wanted Elsa to cook two delicious hens up: one for him, and one for his guest. So, Elsa went to work, and soon the smell of roasting chicken filled the kitchen. Elsa took a quick nap as she cooked, because the cooking usually took several hours.

When Elsa awoke, she had no idea whether the chicken was fully cooked or not. And it smelled so good, hanging there over the fire, so Elsa decided to test it: one wing from one bird should tell her whether the chicken was done or not. So she cut off that wing, and it looked cooked to perfection.

Elsa couldn’t resist – she ate the wing. And now she had a problem: she couldn’t give her master a lopsided bird! So she cut off the other wing and ate it.

But now Elsa realized that she couldn’t give either her master or the guest a bigger bird than the other. So she cut off the wings of the other bird and ate them. In the process, she cut off a bit too much of that bird, so she had to even it out.

In the end, Elsa was left with a bunch of chicken bones where the chickens used to be. And dinner time was fast approaching, so the guest would be there soon.

So Clever Elsa ran past the barn, where her master was sharpening the dinner knives, and ran out to meet his guest on the road. When she caught him, she was a mess: she was panting, sweating, and crying, and she looked deeply worried. The Guest saw this and asked her what was wrong.

“Milord,” Elsa panted, “I come from the house where you are going to have dinner. But my master doesn’t want to have dinner with you. He’s furious, so when you get there he’s going to cut off BOTH OF YOUR EARS!”

The guest heard the master sharpening the knives and was worried, so he thanked Elsa, paid her a bit for her troubles, and started to run away.

Clever Elsa ran back to her master and said, “Master! Master! The guest you invited came early, and he ran off with BOTH CHICKENS I was cooking for dinner!”

The master thought this was quite rude, but didn’t want to look like he wasn’t generous. However, he was hungry, so he ran after the guest, holding the knives he had just sharpened and yelling, “NO! JUST ONE! JUST ONE!”

The Guest, thinking the master was saying he only wanted to cut off one ear, ran even harder.

———————

This story is about communication, and how easy it can be to cause (or solve) trouble with a bit of cleverness and a fast tongue.

Where do we find communication in programming? Why, we find communication most commonly in interfaces and documentation, which we use to tell other programmers how certain pieces of code work, and what they are supposed to do.

What happens when an interface hides something from the end user? Perhaps the code DOES do what was promised, but it also does something that the user didn’t want (like free a passed-in object, or display man-in-the-middle information to an unknown observer)? This little bit of miscommunication can cause any amount of strife, and we only have the interfaces and documentation to reference.

If you are like Elsa, and learn how to communicate exactly what you want, you can either hide malicious (or just buggy) code or you can make everything clear. The power is actually in your hands, because the users are usually just the Master or the Guest.

photo by: