Re: if clause
- From: Richard Heathfield <invalid@xxxxxxxxxxxxxxx>
- Date: Tue, 31 Oct 2006 06:53:58 +0000
Eric Sosman said:
<snip>
Insisting that all modes of failure and all modes of success
must somehow filter down to one great holy return statement is
not good practice, but monotheism run rampant. "Thou shalt have
no RETURN before Me" -- pfui!
Pfui schmui. This isn't about religion, but about clarity. If we can write
the code in a way that a maintenance droid will be able to understand
easily in five years' time, then that's a Good Thing. Personally, I find
code easier to understand if it doesn't arbitrarily leap off a cliff under
certain conditions, at apparently random intervals.
The thing that put me off multiple returns was not success/failure -
bail-out code is easy to understand, and the only caveat is "was it a clean
failure?" (e.g. let's remember to clean up memory, close any files that
shouldn't be open if the operation failed, etc etc). Rather, it was when I
was having to modify long-winded financial calculations that had return
statements sprinkled liberally through the (oversized) function.
Unravelling the "let's squeeze the last nanosecond out of this mainframe"
code so that I could do the mod properly was an exercise in torture. And
one of the worst culprits was this "oh, look, we're in six levels of loop,
this seems a suitably arbitrary place, so let's return the value of this
badly named variable. Or perhaps we should wait until we get to the next
loop, where we can return the value of an *even more* badly named
variable!"
I wouldn't want to put anyone through that. So I don't.
--
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: if clause
- From: Chris Dollin
- Re: if clause
- References:
- if clause
- From: rogz
- Re: if clause
- From: Ancient_Hacker
- Re: if clause
- From: Eric Sosman
- if clause
- Prev by Date: Re: C Interview Questions
- Next by Date: Re: how to design an testing example
- Previous by thread: Re: if clause
- Next by thread: Re: if clause
- Index(es):
Relevant Pages
|
|