Re: while (1) vs. for ( ;; )



"akarl" <fusionfive@xxxxxxxxx> wrote in message
news:glPQe.32705$d5.187496@xxxxxxxxxxxxxxxxxx
> Charlie Gordon wrote:
> > "Chris McDonald" <chris@xxxxxxxxxxxxxxx> wrote in message
> > news:detv2b$ael$1@xxxxxxxxxxxxxxxxxx
> >
> >>Ben Pfaff <blp@xxxxxxxxxxxxxxx> writes:
> >>
> >>I would suggest that both while(1) and for(;;) are potentially unclear
> >>to a person (undergrad. student) seeing C for the first time
> >>(while assuming they haven't seen Java or C++, either).
> >>
> >>OK, I suggest that while(true) is *clearer*.
> >
> In variable and function declarations the virtues of stdbool.h is clear.
> Compare
>
> int isThisAPredicate;
>
> and
>
> bool thisMustBeAPredicate;

You are right, but things are a bit more complicated than this: pretending to
clean up the C language is doomed.
Just look at :

#include <stdbool.h>
#include <ctype.h>
....
while (isdigit(*s) == true) {
... sometime works, sometimes not ?...
}

coming from java, you can be used to writing while(true) { ... } but then this
works too :

#if true
.... this code will compile :
.... It is a good thing the ISO folks made it work... as a consequence, true and
false are plain untyped integral literals.
#endif


I think it is better for people who see C for the first time to not get the
false idea that le language is easy.
The common idiom to loop forever is for (;;) { ... } . It catches the eye
instantly, why make it less obvious by burying semantics in less distinctive
wording ?

I especially don't like while(1) { ... } because it can be confused with while
(l) { ... } and vice versa.
Naming a variable l is of course a bad idea, but a quite common occurrence in
fact.

--
Chqrlie.





.



Relevant Pages

  • Re: Pythonic indentation (or: beating a dead horse)
    ... first time, too. ... my reaction when I first learned of ... Anger and revulsion alone are not the proof of great innovation. ... I probably wouldn't have taken to the language, ...
    (comp.lang.ruby)
  • Re: How to start making own Roguelike game?
    ... This weekend I was teaching programming for the very first time to a friend - of course he wanted to learn "how to make games". ... after a small shoot-em-up demo in it I abandoned it for a more mature+simple platform (Blender Game Engine + Python). ... The language doesn't have to be a good one, just good enough to get you started. ... Programming the basics of a roguelike is very easy and it makes you feel very confident:-D ...
    (rec.games.roguelike.development)
  • Re: Weisensee
    ... I want to thank for this information; this is the first time I ... German language. ... According to my kind of pronounciation: ... Kind regards ...
    (soc.genealogy.german)
  • Re: Vector data type (2nd attempt)
    ... emulated by means of the language itself is: ... productivity impact is imminent, the question ... write something that works properly first and not let yourself be fooled ... this and get it right first time I think you should give up all pretence ...
    (comp.lang.javascript)
  • Re: Customized Normal.dotm
    ... When you change the interface language in Office 2007 and then start Word, it renames your Normal.dotm as Normal.dotm.old and then creates a new Normal.dotm. ... I found this to my cost the first time I changed the language to check something out and then changed it back. ... The installation includes copying a customized Normal.dotm ...
    (microsoft.public.word.docmanagement)