Re: What do you think about the code?



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)
.



Relevant Pages

  • Re: What do you think about the code?
    ... goto outOfLoop; ... The break keyword is just goto in a false ... the whole switch because I don't care if I'm in quotes when checking for the ... quote character and the escape character). ...
    (comp.lang.c)
  • Re: What do you think about the code?
    ... Goto is disliked, as it leads to code that is harder to read. ... goto outOfLoop; ... puts; ...
    (comp.lang.c)
  • Re: What do you think about the code?
    ... Goto is disliked, as it leads to code that is harder to read. ... goto outOfLoop; ... puts; ...
    (comp.lang.c)
  • Re: question?
    ... in general, every guideline will have ... Take for example the infamous goto statement. ... early returns can sometimes hurt code readability... ... In fact 'flags' are ...
    (comp.lang.java.programmer)
  • Re: What do you think about the code?
    ... of a modular design with strict avoidance of goto, ... function that has outgrown its readability. ... the whole switch because I don't care if I'm in quotes when checking for the ... the test for quotes explicitly where required. ...
    (comp.lang.c)