Re: Simple question!
- From: "Arnaud Debaene" <adebaene@xxxxxxxxxxxxxxxx>
- Date: Sat, 8 Jul 2006 11:45:24 +0200
"Michael K. O'Neill" <MikeAThon2000@xxxxxxxxxxxxxxxxxx> a écrit dans le
message de news: %2368VlTioGHA.4240@xxxxxxxxxxxxxxxxxxxxxxx
Do not use gotos.... ever
For goodness sake...
The use of goto's is generally harmful and often leads to terrible,
unstructured code. Its use should be usually be avoided.
But there are plenty of circumstances when a goto is better. The
generalized
"avoid goto's" rule doesn't mean that goto's should never be used, and
it's
silly to impose pedagogical one-size-fits-all rules -- such as "Do not use
gotos.... ever" -- to all situations.
Nonetheless, an introductory book that presents goto wihtout warning about
it's dangerosity deserves the recycle bin IMHO.
There are a few widely-recognizedIn C, I would tend to agree; But in C++? I don't think so....
situations where a goto is perfectly acceptable and maybe superior.
One isBreak your loops into functions and use returns. Having too deeply nested
when trying to exit from a deep loop.
loops inside one function is sign of a bad design anyway...
Another is to consolidate allUse exceptions, that's why they where invented. Also, if used properly,
error-cleanup in one spot, to avoid duplicated code.
exceptions allow for much easier ressources management in case of error, so
that there is no need for error-cleanup (it is taken care of by destructors)
Recent object-oriented languages (that provide exceptions facilty) such as
C# and Java have dismissed goto altogether : their conceptors felt that the
few cases where it may be helpfull were no match for the risk of
ill-structured, unmaintenable, code.
Arnaud
MVP - VC
.
- Follow-Ups:
- Re: Simple question!
- From: Carl Daniel [VC++ MVP]
- Re: Simple question!
- References:
- Re: Simple question!
- From: Brian Muth
- Re: Simple question!
- From: Mark Randall
- Re: Simple question!
- Prev by Date: Re: allocating memory in DLL and returning a handle to the application
- Next by Date: Re: Simple question!
- Previous by thread: Re: Simple question!
- Next by thread: Re: Simple question!
- Index(es):
Relevant Pages
|