Liste des Groupes | Revenir à cl c |
On 21/04/2025 22:06, Waldek Hebisch wrote:bart <bc@freeuk.com> wrote:>
t iteration goes over all elements in the hash table.BTW2: When looking at 'for' loop you are supposed to see pattern,>
without need to track all steps.
That's one of the disadvantages of using the same, often
/inappropriate/ keyword for every kind of pattern.
This is the original C again:
>
for(p=sqliteHashFirst(&pSchema->trigHash); p; p=sqliteHashNext(p)){
sqlite3DeleteTrigger(db, (Trigger*)sqliteHashData(p));
}
>
This is the version that my visualisation tool produced (where C
source is visualised in my syntax); posted earlier but it's worth
posting again:
>
p := pSchema^.trigHash.first
while p do
sqlite3DeleteTrigger(db, ref Trigger(p^.data))
p := p^.next
od
>
While the C version looks intimidating, this looks much cleaner and
simpler (expanding those macros helped).
The intent of 'for' is to iterate over some collection. Each of>
A, B, C is needed to know the collection.
Sure, but ALL ON THE SAME LINE? All within the same parentheses?
Putting multiple things on the same line is usually frowned upon. Look
at these ludicrous examples:
>
for(p=pDel; p && (p->pLeft||p->pRight); p=(p->pLeft ? p->pLeft :
p->pRight)){
>
for (yoffset = coef->MCU_vert_offset; yoffset <
coef->MCU_rows_per_iMCU_row; yoffset++) {
>
for (bi = 0; bi < num_blocks; bi++, start_col +=
compptr->DCT_h_scaled_size) {....}
>
I /think/ the last two are simple iterations!
Notice that that last bit of the last example is nothing to do with
the mechanics of the iteration; it's to do with the body.
>>Especially A, which is only executed once, after which it's no longerWithout A you do not know range of iteration.
part of the loop.
I've seen plenty of for-loops that start with 'for (;...)'; that
doesn't seem to worry anyone! Which is not surprising; nobody seems to
care anything here.
There is no excuse.
And yet, even within the limitations of C, people favour writing
appalling code, when it could be much cleaner. So (1) they don't care;
and (2) try to justify that bad code as being better.
Here's that visualisation example above, converted into C:
>
p = pSchema->trigHash.first;
while (p) {
sqlite3DeleteTrigger(db, ref Trigger(p->data));
p = p->next;
}
>
Compare with the original C at the top.
Les messages affichés proviennent d'usenet.