Tugger the SLUGger!SLUG Mailing List Archives

Re: [SLUG] Your top-ten linux desktop apps

O Plameras <oscarp@xxxxxxxxxxx> wrote:
> In doing so I have a dramatic change in the way my program now behaves.

No. A for loop is just a different way of expressing a while loop;
they're different syntax but identical in behaviour. Watch:

for (initialise; guard; increment) { body }

initialise; while (guard) { body; increment; }

Using a for loop or while loop, you've still explicity stated the
initial state (start of the array), the guard condition (not at the end
of the array yet) and the increment (next position in the array).

> In the modified program  the size of array may be modified at will and
> there is no need to remembering and change the loop.  We may format
> our array anywhere in the application and no need to change the loop.

Only works for static sized arrays, as has been demonstrated, and leads
to insidious hard to detect bugs when you change to dynamic arrays
because they're just pointers.

> This is where the power of C-pointer lies. If I am prepared and able,
> as a programmer, to put good and compact pointer-arithmetic into my
> programs  I'd  get  better and concise C-programs. It is in the ability
> of the C-programmer. He has a fine-grained control as to what should
> happen.

Humans make mistakes. Minimising the impact of the mistakes is a winning
strategy. Ignoring the fact that people make mistakes is a losing
strategy. Use C when you must, something smarter when you can.

Erik said:

> >By contrast, the O'caml mapi function automatically figures out
> >the start and end conditions from what it knows about the array.
> This is what the modified C-program does with the concised while loop.

No it doesn't. You explicity told it the initial state and guard
condition, and also the increment operation. Any language with a foreach
construct will actually figure those out itself. C will not.
Sam "Eddie" Couter  |  mailto:sam@xxxxxxxxxxxxxxxxxxxxx
Debian Developer    |  mailto:eddie@xxxxxxxxxx
                    |  jabber:sam@xxxxxxxxxxxxxxxxxxxx
OpenPGP fingerprint:  A46B 9BB5 3148 7BEA 1F05  5BD5 8530 03AE DE89 C75C

Attachment: signature.asc
Description: Digital signature