5 surprising ways that cooking and coding are remarkably similar

DSC_7204 copy

I’ve always said there are many parallels between coding and cooking, so when our content team approached me about taking to the kitchen for an interactive cooking show, my answer was an immediate “yes.”

After spending a day in the spotlight while filming the first installment of  “Baking with Jonathan,” I spent some time decompressing and realized that a lot of what we did that day while shooting our Interactive Video could be related to coding.

Here are five examples of decoding the recipe that coding cooks will appreciate.

1. Declare all of your variables.

When cooking (especially on video!), it’s often helpful to get all of your ingredients together and measured ahead of time. This is very similar to declaring all of your variables at the beginning of a code block, which some programming languages require.

2. Be procedural.

When writing out a recipe, you have to take care to make sure things are in a logical order so that someone following the instructions doesn’t run into any problems. Little did my grandmother know that when she was filling her recipe book with instructions, she was actually compiling software for my parents – and now my sister and cousins and I – to execute on our kitchen processors.

3. Space management is key.

Counter management is just as important as memory management – every time you malloc a new bowl, cutting board, or rolling pin in your workspace, you’ve got to make sure you get it washed and out of the way before you need that space for another part of the recipe later.

4. Careful with context switching.

Of course, some of your kitchen appliances are limited resources, like the oven, or the number of burners on the stove, and you can pay an efficiency cost for context switching (or, in layman’s terms, changing tasks midstream, resulting in a period of unproductive time). For example, if you start cooking in a small pot but then realize halfway into the recipe that you need a larger pot, you have to transfer to a larger pot, which is cold, as is the burner. This’ll take extra time to heat up to get you back to where you left off, which wastes time in the cooking process.

The same can be said with context switching on a computer. If I change directions midstream, the PC needs to save the current state of the processor into a special memory space, then load the new task on to the processor, which slows everything down.

5. Avoid deadlock.

Luckily, much of the work can be multithreaded (or multitasking to create parts of the recipe), provided you make sure to “lock” during the proper steps. If you aren’t careful, and you get ahead of yourself, it’s easy to deadlock. In coding, “mutex” (short for “mutual exclusion”) is a way to do resource management in a situation where two processes are expecting to use the same resources (or the same counter space).

Deadlock in cooking can easily happen without proper planning. For example, you need the drippings from a roast before you can make Yorkshire pudding, so if you took up the entire counter making the bread part of the Yorkshire pudding recipe, you’d have nowhere to take the roast out and set it, and therefore would be blocking yourself from making the pudding.

Are you a coder who likes to dabble in the kitchen? Let me know if there are any other correlations between cooking and coding that I may’ve missed. Interested in making your own Interactive Video? Click here to get started

Share on FacebookTweet about this on TwitterShare on Google+Share on LinkedInEmail this to someone

View Related Post

Submit a Comment

Your email address will not be published. Required fields are marked *