Analogies can help you!

English: Glas of german "Würzburger Hofbr...

English: Glas of german “Würzburger Hofbräu” beer, enjoy cold! (Photo credit: Wikipedia)


At work, we explain everything with an analogy. Everything you need to explain something here, are beer and cars. Maybe both. But don’t drink and drive. (Achievement unlocked: Role Model)

I give an example: We had the following code-snippet:

public Set<Item> getItems() {
    return items;

Everything fine, not? Our boss came and replaced the code by the following:

public Set<Item> getItems() {
    return Sets.newHashSet(items);

We’re using Google Guava, by the way.

I think it should be clear, why he replaced the code by the second one. We all said “Ah, seems logical” (in this special case, trust me).

However, one of the students asked Why?

My boss thought about that for a while, and came with the following story:

Imagine a special beer shop, I’m the shopkeeper. Now, looper comes in and wants to buy a crate of beer. Somewhere on my shop, I have a sign where I store a beer crate. I tell looper, what is written on the sign; now he knows where he can find his beer crate.

Now comes anon, and wants a beer crate, too. I read point at the sign and he knows where the crate is. He remembers it and goes home, to take it later.

However, looper waiting for his girlfriend, decides to drink a little bit of beer. After one hour of waiting, he emptied the crate. Now he’s drunk like a [Insert German joke here].

Not only his girlfriend is angry now, anon sees that his crate is empty! Damn. Now his friends can’t drink with him. But hey, I have sold the same crate two times. At least I can be happy.

Now imagine, I could duplicate the beer. (He’s really a magican.) I hand one list to looper, and the moment you want a crate, too, you get a brand-new list! That’s why we create a new list with the same content here. Now looper has a crate, and you have another crate, but both have the same content. Looper now can’t drink your beer, because you have an other crate, like a copy.

The result is: looper is still drunk, his girlfriend is still angry, and in comparison to the first try, I now got the same money for more products. Hm. But hey, anon and his friends are happy now. At least something.

With that analogy, he finally understood the reason. That’s not the only occurrence of analogies at work, but I really liked that one. Maybe later, I’ll post some more.

And, by the way, that example can easily be expanded for explaining call by reference/by value and the difference between the same and the identical . But I guess that should have another place ;).

One last thought: Maybe I used the word beer too often. WordPress suggests only “Beer”, “Beer”, “Beer” and “Beer”. Hm. And I don’t even drink beer.

Tagged , , , , ,

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: