Re: break, continue, goto
Re: break, continue, goto
- Subject: Re: break, continue, goto
- From: "Alastair J.Houghton" <email@hidden>
- Date: Wed, 6 Aug 2003 13:02:24 +0100
On Wednesday, August 6, 2003, at 10:04 am, Yuhui wrote:
Alastair,
While I can understand the use for a goto, I've learned in my
experience that most goto's can be replaced with methods. I think
there's more flexibility with methods because you can more easily
"expand" them to accomodate bug fixes or add new features/functions.
Also, if there are several goto statements in different parts of the
program that use a particular block of code, then methods would reduce
redundancy.
I think you've missed the point; from what you've just said, I would
guess that you have a background in BASIC or scripting languages, where
goto can jump anywhere (and therefore a *lot* of uses of goto in those
languages are indeed, as you say, better replaced with function calls).
By contrast, in C, you can only jump within the current function, and
you aren't allowed to jump into a block (although you can jump out of
one), which means goto can't be used as a mechanism for sharing code
between different areas of your program. Not unless your entire
program is one big function, at any rate, and *that*, frankly, is a far
worse crime than using goto ;-)
Whilst I don't want to get into an argument about programming style, I
will say that IMO, in the specific cases I highlighted, goto is
probably the best solution (or in case (c), at least deserves
consideration). I also (personally speaking) feel that using (or
trying to use) functions in order to avoid goto even in situations
where it *is* appropriate will make your program harder to read and
probably (in the long run) more brittle.
In any case, the main point I was trying to make the point that it
isn't sensible to discount goto (or break, or continue, or for that
matter any other construct) solely on the basis that you have been told
by somebody else that it is always bad and should never be used.
Kind regards,
Alastair.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.