Re: What do you think about the code?
- From: Ian Collins <ian-news@xxxxxxxxxxx>
- Date: Sun, 02 Jul 2006 08:24:06 +1200
Andrew Poelstra wrote:
On 2006-07-01, Richard Heathfield <invalid@xxxxxxxxxxxxxxx> wrote:I agree 100% with Richard's comments, the cleaner the code structure,
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.
Since as a maintenance programmer you've probably had to deal with a lot of
similar code, suppose you were writing a parser and you did this:
c = get_input();
if (we_are_in_a_quote && c != '\"')
goto skip_parsing;
switch (c)
{
/* Parsing code here */
}
skip_parsing:
/* Return parsed text to callee. */
Would that be an appropriate use of goto? Otherwise I've found that I end up
with if statements around most every single case block. (I can't do it around
the whole switch because I don't care if I'm in quotes when checking for the
quote character and the escape character).
the easier it is to refactor. That's why my last team banned goto outright.
In the parser example, I would call a function for each case and include
the test for quotes explicitly where required. I think this makes the
code clearer.
--
Ian Collins.
.
- Follow-Ups:
- Re: What do you think about the code?
- From: Frederick Gotham
- Re: What do you think about the code?
- References:
- Re: What do you think about the code?
- From: Richard Heathfield
- Re: What do you think about the code?
- From: Andrew Poelstra
- Re: What do you think about the code?
- Prev by Date: Re: Printing string constants
- Next by Date: Re: What do you think about the code?
- 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
|