Pro Programmer
Coding Real Life Analogies

Writing Cooking Recipes!

If you think you learned something, try teaching it. Teaching a topic is the ultimate test of your knowledge of it. Try to teach an absolute beginner how to code. You will love it!

To take this a bit further, the ultimate challenge is to be able to teach young kids about what you know. This requires explanation with ultimate clarity and only someone who completely understands a topic can do that. When it comes to teaching kids, simple real-life analogies can really help.

I love thinking about coding concepts by comparing them to familiar things we know in life. There are so many analogies out there about coding concepts. Some of them are good while others are confusing, mainly because they focus on partial aspects of a concept while ignoring many others. This article will summarize some of the analogies that I think best fit a few coding concepts in complete ways.

I will start with simple concepts and move on to harder ones. Let’s start with coding itself. Coding can be compared to writing cooking recipes. A recipe in this analogy is the program and the cook is the computer. A recipe is a list of instructions for a cook to follow and a program is a list of instructions for a computer to execute.

This is a very simple analogy given that a recipe is written in a human language and a program is written in a computer language and those are very different languages (unless your recipes have closures and promises!).

There are also not a lot of unexpected things to plan for in a recipe while a computer program will have many. Regardless of its simplicity, it is a good way to show how a computer carries out a list of instructions sequentially. It also shows where one instruction line can use any result from executing prior instruction lines.

Some recipes will even have if-statements: if cooking for 2, 4 or 8! Some recipes will have loops: keep beating that mix until…

I also like this analogy because of all the ready items and tools that you can use in your recipes — like the cake mix that you can use to make cupcakes and that specially-shaped pan that makes it so much easier to create cupcakes.

The use of ready items and tools is like including and using a package of code written by others in your own code.

// The making of a cupcake

// First steps:
$ npm install cake-mix
$ npm install cupcake-pan

NPM is the package manager for Node.js, which a very popular framework for writing JavaScript applications. In this analogy, Node.js is like the kitchen itself. It allows you to execute lines in your recipes by using built-in modules like your oven and sink.

Speaking of unhealthy food, this next analogy is for learning how to code and is compared to eating habits. I particularly LOVE this analogy and what it conveys because it helps me to stay on track in my code-learning journey. For me, this began in high school and will continue until my brain reaches its last instruction: die();