|
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
|
Re: [PLUG] 'goto' in C code
|
> Does anyone have a reason why goto should not be used in C code ??
>
> I like to use it for error handling, but a couple managers where I work
> have this idea that the goto keyword should never be used, although they
> can't offer any reason why. I have heard before that it's not good
> practice, but I've never heard a valid reason why. Can anyone shed some
> light ?
I've seen it used effectivly by a very experienced devleoper. I've also
seen other less experienced developers try to maintain that code, and not
be able to do it effectivly.
It's not a black and white issue -- for error handling, can you use
setjmp/longjmp instead of the goto? That might give you the "get out
of there quick" feature of the goto, and make your manager happy. Have
you thought about C++ -- the exception handling can be a real benefit,
even if you don't use other features of the language.
goto's tend to create code that's harder to follow, and harder to maintain.
When you use a goto, you circumvent normal language features (such as scope -
brackets) to control the flow of the program, this can make things harder to
debug, follow, and maintain. I've been a developer for going on 7 years
now, and havn't used one yet. Not that I've ruled them out, I just havn't
written code where I thought that the benefits of using one out weighed the
penalties.
k
------------------------------------------------------------------------------
guru, n: A computer owner who can read the manual.
-- Anonymous
mortis@voicenet.com http://www.voicenet.com/~mortis
------------------------------------------------------------------------------
______________________________________________________________________
Philadelphia Linux Users Group - http://www.phillylinux.org
Announcements - http://lists.phillylinux.org/mail/listinfo/plug-announce
General Discussion - http://lists.phillylinux.org/mail/listinfo/plug
|
|