home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!munnari.oz.au!metro!extro.ucc.su.OZ.AU!maxtal
- From: maxtal@extro.ucc.su.OZ.AU (John MAX Skaller)
- Subject: Re: Improvements on C++?
- Message-ID: <1992Dec12.144301.25735@ucc.su.OZ.AU>
- Sender: news@ucc.su.OZ.AU
- Nntp-Posting-Host: extro.ucc.su.oz.au
- Organization: MAXTAL P/L C/- University Computing Centre, Sydney
- References: <1992Dec4.103551.664@netcom.com> <1992Dec8.165230.2587@ucc.su.OZ.AU> <1992Dec9.124436.20197@druid.uucp>
- Date: Sat, 12 Dec 1992 14:43:01 GMT
- Lines: 39
-
- In article <1992Dec9.124436.20197@druid.uucp> darcy@druid.uucp (D'Arcy J.M. Cain) writes:
- >maxtal@extro.ucc.su.OZ.AU (John MAX Skaller) writes:
- >>but one may need
- >> while(p=get()) { ... }
- >>instead of
- >> p=get();
- >> while(p) { ... p=get();}
- >>sometimes for speed and clarity.
- >
- >You can still do this without sacrificing speed and in fact enhance clarity:
- >
- > while ((p = get()) != 0) {...}
-
- The five extra characters make this clearer?
- >
- >I write this way all the time, even on systems that don't warn about that
- >construct. It leaves no doubt in the future maintainer's mind exactly
- >what I meant to do.
- >
-
- This is a mixed metaphor, puting 'p=get()' in the while()
- part is a C idiom, not requiring !=0 is a C idiom. Using
-
- p=get();
- while(p!=0) { ... p=get(); }
-
- would be the 'pascal' like idiom. (I'm just making a light
- comment, this is a stylistic issue we shouldn't start a war about..
- try:
-
- WHILE not (p is 0) DO ... ENDDO
-
- which is perfectly legal C (with macros) if you want to starty a war:-)
-
- --
- ;----------------------------------------------------------------------
- JOHN (MAX) SKALLER, maxtal@extro.ucc.su.oz.au
- Maxtal Pty Ltd, 6 MacKay St ASHFIELD, NSW 2131, AUSTRALIA
- ;--------------- SCIENTIFIC AND ENGINEERING SOFTWARE ------------------
-