home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / cplus / 13265 < prev    next >
Encoding:
Text File  |  1992-09-03  |  1.6 KB  |  53 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!stanford.edu!ames!decwrl!borland.com!pete
  3. From: pete@genghis.borland.com (Pete Becker)
  4. Subject: Re: GOTO, was: Tiny proposal for na
  5. Message-ID: <1992Sep3.170535.6424@genghis.borland.com>
  6. Originator: pete@genghis.borland.com
  7. Sender: news@borland.com (News Admin)
  8. Organization: Borland International
  9. References: <4192@papaya.bbn.com> <1992Sep2.155510.4274@genghis.borland.com> <600@lax.lax.pe-nelson.com>
  10. Date: Thu, 3 Sep 1992 17:05:35 GMT
  11. Lines: 40
  12.  
  13. In article <600@lax.lax.pe-nelson.com> twbrown@PE-Nelson.COM (Tom W. Brown) writes:
  14. >In article <1992Sep2.155510.4274@genghis.borland.com>, pete@genghis.borland.com (Pete Becker) writes:
  15. >|> 
  16. >|> C++ version:
  17. >|> 
  18. >|> void foo()
  19. >|> {
  20. >|>     ifstream input( "foo" );
  21. >|>     DataObject data;
  22. >|>     if( data.doStuff( input ) == ERROR )
  23. >|>         return;
  24. >|>     data.doMoreStuff();
  25. >|> }
  26. >|> 
  27. >|>     Let the compiler do the work...
  28. >|>     -- Pete
  29. >
  30. >Tsk, tsk, tsk... You put a return in the middle of the function :-)
  31.  
  32.     Yes, and quite deliberately.
  33.  
  34. >How about:
  35. >
  36. >   void foo()
  37. >   {
  38. >      ifstream input("foo");
  39. >      DataObject data;
  40. >      if (data.doStuff(input) != ERROR)
  41. >         data.doMoreStuff();
  42. >   }
  43. >
  44.  
  45.     I use a return in the middle of a function whenever processing within
  46. that function has terminated.  This is usually because of an error, but it
  47. is sometimes because a very simple case has been identified and handled.  If
  48. instead of data.doMoreStuff() there had been 30 lines of code, it's much 
  49. clearer to me to have the conditional return followed by that code, rather
  50. than adding a block and indenting everything.
  51.     -- Pete
  52.  
  53.