Over the past few years I’ve gotten heavily into cooking — thanks in large part to my beloved friend Joelle who introduced me to the concept of a CSA.** Now that we live in Durham and I’ve been spending my days coding and my evenings cooking, I’ve realized they have a lot in common.

We’ve heard of coding rockstars, monkeys, artists — but what about coding chefs? There is even an infrastructure automation technology called Chef, complete with cookbooks, workstations, and recipes. So where does the parallel come from?

1. Use Everything You’ve Got

One of my favorite challenges in the kitchen is creating what I can with what I have at hand. Rather than discard the water in which you just cooked beets, use it to flavor your couscous. Turn your leftover curry into a spicy omelette in the morning. Pesto is my favorite scrappy project — it can be made from any nut and greens combo you have on hand.

When coding, programmers follow similar principles. No code should be repeated; rather than referencing the same thing twice, identify patterns and extract them into separate methods. Avoid redundant variables and unnecessary logic. A failure to do this is known as “code bloat”, which can be messy, confusing and worst of all wasteful.

2. Borrow Tools From Others

Jarred salsa. Ready-made pie crust. Pre-grated cheese. Even canned beans. These are frequently used items in a well-worn kitchen, and we buy these items pre-made even though they aren’t tough to make from scratch. Yes, there is satisfaction in baking your own challah or pickling your own green beans, but there’s someone out there who already did this for you.

In Ruby, this concept is known as gems, which you install onto your computer to help meet a specific need; for example, ‘byebug’ makes it way easier to debug code; ‘faker’ auto-generates fake user data; there is even a gem called ‘bundler’ which bundle installs other gems. When it comes to the needs of developers, “there is [almost always] a gem for that.” Anyone can make gems, and you can use ‘em! To date, there have been over 6 billion downloads of Ruby gems.

3. Oh So Many Options

There are many ways to do something; some methods give better results, but are more time consuming or harder to access. I can try to squeeze juice out of kale or I can use a juicer. I can make my rice in a pot — it just won’t taste as consistent as a rice cooker. But sometimes fancy equipment does not yield a better result — every purist knows that latkes just taste better if you grate the potatoes by hand.

Similarly in code, there are many ways to satisfy a requirement. Some are more concise than others, but fewer lines isn’t always synonymous with more efficient. In fact, the shortest way can harm the code’s readability, which is often more important since most projects have multiple programmers working on them. For example, in a game of Battleship I can decide how to print hits and misses on the board with:

has_ship_on?(x, y) ? @locations(x, y).fired_upon ? (print " X |") : (print " O |") : (print " |")

or I can write it out a bit differently:

if (has_ship_on?(x, y) && @locations(x, y).fired_upon == false)

(print "| O ")

elsif (has_ship_on?(x, y) && @locations(x,y).fired_upon == true)

(print "| X ") else (print "| ")

end

Although the former is much shorter, it can make it difficult to understand at a glance what the code is communicating.

4. Micro-Task

When it comes to cooking, meals are broken down into their smallest parts. We chop the vegetables, toast the walnuts, and make the dressing. Then, we taste. Sometimes it tastes great and we move on; but most of the time, it needs salt or oil or spices. Eventually, we taste all the components together to make sure they blend. Then comes the garnish, the plating, and the presentation.

Similarly, programmers code the smallest tasks at a time in order to incorporate feedback rapidly and modify direction according to changing requirements. For example, before I can modify the total salary of all employees in a department, I have to create the concept of a department that can contain another concept called employees. I write regression tests to ensure that my latest components are not causing errors or failures in what I’ve already built. And at the end, I go back through my code to refine, refactor, clean.

5. Comradery and Community

There are some people you cook with easefully. You hand them the greens, they start to chop garlic. With another person nearby and able to provide feedback and ideas, we find ourselves trying more adventurous things in the kitchen. And feeling part of a community — whether it’s locavores, vegans, or sausage aficionados — helps connect us to other people who share our love for the craft.

The same is true for coding. Oftentimes with pair programming, focus and discipline are intensified, code is higher quality, and there is time for mentorship and team bonding. And the Ruby on Rails community is bustling with activity and support; in fact, their website reads, “The community is full of nice people who want to help others learn.” Meetups and conferences are plentiful, and questions posted online are often answered within minutes.

6. Holy Crap I Did It!

For a dish to succeed, it needs a combination of skill and artistry. Without the subtle touches of aroma and presentation, the food might taste good but it will still fall flat. It is deeply satisfying to serve a dish you’re proud of to your loved ones. My best friends and I keep a shared blog with pictures and recipes, although it’s been a while since we posted. [I blame the distractions of summer, but ladies, if you’re reading this, POST. xo]

The same is true of coding. A quick Google search of the “feeling you get when your code finally works” returned a gif of gleeful minions, a scene from Castaway of a triumphant Tom Hanks, and the moment from Billy Madison when Adam Sandler yells, “I AM THE SMARTEST MAN ALIVE!” This sense of accomplishment is incredible, it’s best described as childish delight.

If only it were as popular to post screenshots of your code on Instagram.

_____________________________________________________________________________

** A CSA means that each week, I get a portion of a farmer’s crop — whatever is growing locally — and I macgyver it into an edible meal.

[Shameless plug: Joelle’s CSA in Brooklyn Heights is delicious AND does its part by subsidizing the CSA in Crown Heights. Try it.]