home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / cplus / 17855 < prev    next >
Encoding:
Text File  |  1992-12-12  |  1.8 KB  |  52 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!munnari.oz.au!metro!extro.ucc.su.OZ.AU!maxtal
  3. From: maxtal@extro.ucc.su.OZ.AU (John MAX Skaller)
  4. Subject: Re: Improvements on C++?
  5. Message-ID: <1992Dec12.144301.25735@ucc.su.OZ.AU>
  6. Sender: news@ucc.su.OZ.AU
  7. Nntp-Posting-Host: extro.ucc.su.oz.au
  8. Organization: MAXTAL P/L C/- University Computing Centre, Sydney
  9. References: <1992Dec4.103551.664@netcom.com> <1992Dec8.165230.2587@ucc.su.OZ.AU> <1992Dec9.124436.20197@druid.uucp>
  10. Date: Sat, 12 Dec 1992 14:43:01 GMT
  11. Lines: 39
  12.  
  13. In article <1992Dec9.124436.20197@druid.uucp> darcy@druid.uucp (D'Arcy J.M. Cain) writes:
  14. >maxtal@extro.ucc.su.OZ.AU (John MAX Skaller) writes:
  15. >>but one may need
  16. >>    while(p=get()) { ... }
  17. >>instead of
  18. >>    p=get();
  19. >>    while(p) { ... p=get();}
  20. >>sometimes for speed and clarity.
  21. >
  22. >You can still do this without sacrificing speed and in fact enhance clarity:
  23. >
  24. >    while ((p = get()) != 0) {...}
  25.  
  26.     The five extra characters make this clearer?
  27. >
  28. >I write this way all the time, even on systems that don't warn about that
  29. >construct.  It leaves no doubt in the future maintainer's mind exactly
  30. >what I meant to do.
  31. >
  32.  
  33.     This is a mixed metaphor, puting 'p=get()' in the while()
  34. part is a C idiom, not requiring !=0 is a C idiom. Using
  35.  
  36.     p=get();
  37.     while(p!=0) { ... p=get(); }
  38.  
  39. would be the 'pascal' like idiom. (I'm just making a light
  40. comment, this is a stylistic issue we shouldn't start a war about..
  41. try:
  42.  
  43.     WHILE not (p is 0) DO ... ENDDO
  44.  
  45. which is perfectly legal C (with macros) if you want to starty a war:-)
  46.  
  47. -- 
  48. ;----------------------------------------------------------------------
  49.         JOHN (MAX) SKALLER,         maxtal@extro.ucc.su.oz.au
  50.     Maxtal Pty Ltd, 6 MacKay St ASHFIELD, NSW 2131, AUSTRALIA
  51. ;--------------- SCIENTIFIC AND ENGINEERING SOFTWARE ------------------
  52.