Lately, I have been learning how to cook. While I am at it, I realize how very similar it is to my experience of writing code. The feeling of accomplishment and satisfaction I get when a snippet of code finally runs without errors is remarkably similar to the feeling of seeing a dish come together just right.
I think this similarity stems from the fact that both, coding and cooking are processes that involve careful planning, attention to detail and a bit of experimental troubleshooting.
Recipes vs Algorithms
When I read recipes, my brain interprets them as algorithms i.e. I look at them as a systematic set of instructions that are intended to create a specific output. This is very much like following the syntax of a code and writing specific functions to create an output.
In cooking, I have to carefully plan and prepare all the ingredients before I actually start cooking. This is similar to how I have to first carefully plan the tech stack of a program before I start writing code and I have to make a choice of which libraries and database schemas to use.
Flavours vs Functions
When the actual cooking begins, I can see how different foods interact with each other to create a complex flavour. This is again similar to how different functions in a class of code interact with each other to create a complex procedural output.
If we modify the order or quantity of the ingredients, the flavour changes. Similarly if we pass different attributes to a function, the output changes.
Salt vs Debugging
No matter how carefully I plan and cook a dish, I tend to miss out on something (usually salt and spices) that I have to adjust later. It’s not until the last stages of cooking that I realize this and then I have to add these missing elements in the end to make sure that the dish tastes just about right.
Similarly, no matter how detailed the system design is, getting unexpected runtime errors is inevitable. It is then followed by a session of debugging before the code finally runs fine.
Conclusion
At the end of both the endevaours, there’s this magical moment when everything works just perfectly. In coding, it’s when you run the program, and it executes flawlessly. In cooking, it’s when you taste the dish, and the flavours are just right. That feeling of accomplishment of seeing your efforts come to fruition is unmatched!