Liste des Groupes | Revenir à cl c |
On 22/04/2025 09:54, Janis Papanagnou wrote:Well C's would be:On 21.04.2025 17:36, bart wrote:Alternatively, you might describe it as "Perform the task on each element" :On 21/04/2025 14:51, Waldek Hebisch wrote:>>>
[ sqlite3.c code ]
You have to analyse it first. The kind of loop this expresses is:
No. That's just *your* _transcription_ of the original code
>p = startvalue()>
>
while (p) {
<body>
p = nextvalue()
}
>
Notice how I chose to express it: it reflects how I would describe it in
English:
You are *not* describing _the task_, you are merely translating the
_chosen commands_ of the procedural language [that you have chosen]
>>>
* Set P to Start Value
* While P isn't Null:
* Execute the body
* Set P to Next Value
Whatever programming language and constructs you use, this is not
more than a rephrasing the used language constructs (as opposed to
the task).
>
(It's not surprising; you can observe that folks that are familiar
only with imperative languages tend to this sort of fallacy.)
>So, how would /you/ describe it in English? (Or in any language if like,>
as the ordering is more important.)
Iterate over the elements and sequentially perform <the task> on
the elements. Or a bit more formally
>
iterate (elements, task)
>
in some functional programming language. Or any other variant on
any abstraction level that is appropriate.
>
task(e) for e in elements
Sometimes you want to emphasise moving through the elements, sometimes you want to emphasise what you are doing with them - but either way is fine.
You may or may not include an order in the iteration, depending on what you actually want to do here (I have no idea of the purpose of the original code).
I would suggest Bart thinks this through using a real-world task. Consider making a cake by mixing the ingredients you have laid out on your kitchen top. Would you use Janis' formulation?
Go through the ingredients, putting each in the bowl.
Or mine?
Put in the bowl each of the ingredients.
Or Bart's ?
Stand in front of the first ingredient.
While you have an ingredient in front of you :
Put the ingredient in the bowl.
Move to the next ingredient.
Les messages affichés proviennent d'usenet.