jump to navigation

An Analogy for Types January 14, 2017

Posted by PythonGuy in Uncategorized.

Sometimes the best way to teach a principle is to share an analogy.

Let’s come up with an analogy of types. Let’s say your program is a set of instructions you give to Amelia Bedelia.

Now, suppose Amelia Bedelia needed you to spell out what type of everything you refer to. “Please, Amelia Bedelia, bake a cake” becomes “bake (a function which takes a recipe for something bakeable) a cake (an instance of the cake class, which is a bakeable item).

Versus, “Bake a cake”.

See the point?

Now, if you told Amelia Bedelia “bake a shoe”, in a dynamic, strong typed system, she would look for the recipe for baking a shoe, and not finding one, would say, “I can’t do that. I can’t find the recipe for a shoe.”

Either way, the end result is the same. The question is when does Amelia Bedelia tell you she can’t do it: right after you tell her, or when she realizes she can’t do it.

But remember how hard it was to tell the strict/weakly typed Amelia Bedelia to bake a cake?



1. codeinfig - January 14, 2017

youre right– dynamic/duck typing is easier to teach. it maximizes the number of people who can code, without being horrible in any way (theres nothing truly horrible about dynamic/duck typing.)

its not the right tool for every single job, but its a good tool for most jobs. youre not writing something mission critical, or low-level like a kernel driver? raw speed isnt something youre trying to maximize? then dynamic/duck typing is the general-purpose way to focus on getting stuff done with less hassle: https://www.youtube.com/watch?v=ZD71JeX4Vk0

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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: