In the last installment, I was left wondering why recipes have rules rules above and beyond normal English language rules. What is so special about a recipe?
If I want to talk about onions, I should be able to talk about onions! Recipes only allow me to talk about onions if I list them in the ingredients… Not Fair! Why do recipes feel the need to rain on my love parade? Why is it so important that they put me down?
Because I’m not taking any sort of scientific approach, let’s play around with the idea of what a recipe is. Let’s not try and prove anything or develop any kind of convincing argument, lets just muck around with recipes.
Can you read a recipe? Absolutely!
Can you write a recipe? Of course!
Can you vacuum the living room with a recipe? Ummm… maybe if the recipe calls for vacuuming.
Can you marry a recipe? Probably not, recipes aren’t animate.
Can you date a recipe? Maybe by adding figs. As inanimate objects, they’re not very relational.
Can you follow a recipe? Yes, you can, even though recipes aren’t animate and they don’t move anywhere of their own volition.
Can you obey a recipe? Yes you can, they contain instructions. ‘Obey’ is a synonym for ‘Follow’ when talking about recipes.
Can you make a recipe? Yes you can. Generally making a recipe means to make whatever the recipe tells you, rather than the recipe itself. Generally if we talk about the construction of the recipes themselves, we are forced to say that we write the recipe.
Can you execute a recipe? Hmm….
Can you execute a recipe? It’s not common terminology….
Can you execute a recipe? Yes, why yes you can!
Recipes are programs, and that the language we write recipes in is a programming language.
| Recipe | C Program |
|---|---|
AjvarYield: 6 servings
Bake eggplants and sweet peppers at 350 F until tender when pierced with a fork. Peel skin from hot vegetables and chop or mince the vegetables.Season to taste with salt and pepper and stir in the garlic and lemon juice. Gradually stir in as much of the oil as the vegetables will absorb. Mix well. Pile into a glass dish and sprinkle with parsley. |
#include <stdio.h>
int i = 0;
char string[] = "Pretty smooth\n";
float f;
int main(void){
f = 2.0;
printf("%d and %f \n",i,f+i);
printf(string);
}
|
The big difference between a recipe and a C program of course, is that one was written to be executed by a human and the other was written to executed by a C compiler and a microprocessor. One produces food to be eaten, and the other produces a computer program which can be run.
The reason I’ve listed both side by side is because they’re essentially the same. Both start out with a few declarations, “You have two eggplants,” “You have an integer named ‘i’”, and then continue with some instructions as to what to do with the declared items.
Incidentally, if you try to write a C program where you work with undeclared variables, the compiler will complain and spit out several errors. If you write a recipe with undeclared ingredients, the cooks who try and make your recipe will encounter similar “Does not compute” moments. Both the recipe and the C program are simple procedural programs.
I think in the next post I’ll look at the differences between writing programs for people and programs for computers.