Re: What do you think about the code?
- From: Richard Heathfield <invalid@xxxxxxxxxxxxxxx>
- Date: Sat, 01 Jul 2006 16:24:55 +0000
Andrew Poelstra said:
<snip>
What is easier to read:
/* Start */
while (test[0])
while (test[1])
while (test[2])
{
if (test[3])
goto outOfLoop;
}
outOfLoop:
puts ("Escaped from loop.");
Now add sixty to a hundred lines of actual code, ten lines of comments, and
a couple of years of maintenance, and /then/ ask me whether this is easy to
read.
Or, without goto:
Unstructured version snipped. The break keyword is just goto in a false
moustache.
In practice, status objects are cheap and readable. If they are becoming
unreadable, it's a sign that your function is too big. One huge advantage
of a modular design with strict avoidance of goto, non-documentary
continue, and switchless break, is that it is really easy to refactor a
function that has outgrown its readability. Just chop out the innermost
loop, dump it into a new function, and that's typically almost all that you
have to do. When the control flow is hopping all over the place like a frog
on his wedding night, code simplification is far more difficult to achieve.
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
.
- Follow-Ups:
- Re: What do you think about the code?
- From: Andrew Poelstra
- Re: What do you think about the code?
- Prev by Date: Re: Greatest number divisible by Y
- Next by Date: Re: 'clear' shell command in Makefile
- Previous by thread: Re: What do you think about the code?
- Next by thread: Re: What do you think about the code?
- Index(es):
Relevant Pages
|