jump to navigation

Software engineering principles exemplified with cooking recipes August 15, 2015

Posted by Ezra Resnick in Computer science.
1 comment so far

Don’t Repeat Yourself

Bad:

Add an inch or two of water to a pot. Insert a colander above the water, and bring the water to a boil. Add broccoli in bite-sized pieces. Cover the pot and cook for a few minutes, until tender.

Add an inch or two of water to a pot. Insert a colander above the water, and bring the water to a boil. Add cauliflower in bite-sized pieces. Cover the pot and cook for a few minutes, until tender.

Better:

Steam broccoli and cauliflower. (See sidebar on how to steam vegetables.)

Modularity (Low Coupling)

Bad:

Push the “Start” button on the left side of the oven, then push the “plus” button until the temperature display reads 350. Wait 15 minutes. Put cookies in the oven for 27.5 minutes.

Better:

Preheat oven to 350 degrees (see oven’s instruction manual). Bake cookies for 20-30 minutes, until firm and brown.

Abstraction

Bad:

Milk a cow, and let the fresh milk rest in a cool place for 24 hours. Skim the layer of cream off the surface and pour into a container. Shake the container for 30 minutes. Filter through a gauze to eliminate the liquid. Put into a mold and chill.

Better:

Buy some butter at the store.

cow-butter

Advertisements