home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!stanford.edu!ames!decwrl!borland.com!pete
- From: pete@genghis.borland.com (Pete Becker)
- Subject: Re: GOTO, was: Tiny proposal for na
- Message-ID: <1992Sep3.170535.6424@genghis.borland.com>
- Originator: pete@genghis.borland.com
- Sender: news@borland.com (News Admin)
- Organization: Borland International
- References: <4192@papaya.bbn.com> <1992Sep2.155510.4274@genghis.borland.com> <600@lax.lax.pe-nelson.com>
- Date: Thu, 3 Sep 1992 17:05:35 GMT
- Lines: 40
-
- In article <600@lax.lax.pe-nelson.com> twbrown@PE-Nelson.COM (Tom W. Brown) writes:
- >In article <1992Sep2.155510.4274@genghis.borland.com>, pete@genghis.borland.com (Pete Becker) writes:
- >|>
- >|> C++ version:
- >|>
- >|> void foo()
- >|> {
- >|> ifstream input( "foo" );
- >|> DataObject data;
- >|> if( data.doStuff( input ) == ERROR )
- >|> return;
- >|> data.doMoreStuff();
- >|> }
- >|>
- >|> Let the compiler do the work...
- >|> -- Pete
- >
- >Tsk, tsk, tsk... You put a return in the middle of the function :-)
-
- Yes, and quite deliberately.
-
- >How about:
- >
- > void foo()
- > {
- > ifstream input("foo");
- > DataObject data;
- > if (data.doStuff(input) != ERROR)
- > data.doMoreStuff();
- > }
- >
-
- I use a return in the middle of a function whenever processing within
- that function has terminated. This is usually because of an error, but it
- is sometimes because a very simple case has been identified and handled. If
- instead of data.doMoreStuff() there had been 30 lines of code, it's much
- clearer to me to have the conditional return followed by that code, rather
- than adding a block and indenting everything.
- -- Pete
-
-