Is the algorithm-recipe analogy a good or a bad one? I am growing suspects that the ubiquitous analogy between algorithms and recipes be not so well founded, especially for theoretically oriented students. I am wondering if this may contribute to the evidence of students having difficulties with even simple loops. I believe that bad analogies make more harm than no analogies, so I ask.

My wondering is that recipes, if superficially similar to the idea of sequential steps, do not really encode the logic that is sought to be explained: the logic of state transitions.
Of course there are state transitions in recipes, but i do not feel they being the characterising properties, nor are they the target of attention (I also like cooking). State transitions in recipes (and similar physical operations analogies) seem to be not even caused by the "program" but just happening because of physics. And typically what we get from students struggles is exactly their inability to follow (or design) state transitions. Probably because a fundamental property of a real computer program is that of being the acting cause and not the observer of state transitions, and this is not captured by the analogy. Another issue is that computing systems are typically discrete while physical analogies tend to be continuous, both in time and measured (variables) dimensions.

What screams for attention in recipes are instead "data" dependency constraints (cannot throw in the spaghetti before the water boils), or a kind of "event-driven" situation, and i do not recall seeing students struggling with data dependencies, which might be because 1. the recipe analogy is good in teaching them or (I suspect more probably) 2. it's not what they need help for: data dependencies being more innate than state transitions, especially in a forcefully sequential environment (of course this is a hypothesis, any experiments known?).

On a more concrete side it seems to me that the real world software counterpart of recipes are those things that we usually call scripts: something I love and had made a lot of and which I know perfectly fit their niche problems, but not something that is known for exposing nice theoretical properties, which, I suspect, is what matters more when learning, in order to build a clear mental model of algorithms (and because my pupils are generic science students and not specialist computer developers).

Realistic programs, and especially subprograms if we want to divide et impera, are not sequences of operations but sequences of state transitions.

What do you think of this analysis? Have any empirical data? Does an analogy that takes more care of state transitions exist and I have missed it?
Actually, you are loading a metaphor/analogy with too much import and influence. An analogy isn't supposed to be exactly the same thing as the thing of which it is an analogy. It is only supposed to be similar to that thing in some way. But not in all ways. 

Analogies and metaphors in teaching computing are intended only to overcome the initial static inertia caused when a student has no idea whatever about a concept. To use it well, you need to do a couple of things, one of which is to move away from it as soon as is possible. But the more important thing is to be aware of how the analogy fails to be the thing analogized and to watch for misconceptions in the student's mind that are actually induced by the analogy itself. You then need to give a correcting lesson. 

I can analogize loops with cooking recipes as: stir the sauce until it thickens. This isn't an algorithm, of course, since it has undefined terms, especially in the stopping condition. If that gives the students a quick mental picture of repetition then fine. But if they put too much weight on "stir" or think that an imprecise stopping condition is normal in programming, then I need to make a correction. 

Sometimes that correction is with another, better analogy, but usually it is just a more precise and technical discussion. 

Don't put so much weight on any given metaphor. Use it to introduce concepts but know when it fails and make corrections for those (hopefully few) students who draw the wrong conclusion. You can thus avoid being overly detailed and pedantic, losing students in the interactions between all of the small bits that go into anything complex. 



I've been told that professional bakers follow their recipes more faithfully than professional chefs do. More careful measuring, for example. But even bakers have to deviate as the flour they use can vary in moisture content, requiring adjustments.