Re: if clause



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



Relevant Pages

  • Re: if clause
    ... Insisting that all modes of failure and all modes of success ... bail-out code is easy to understand, and the only caveat is "was it a clean ... one of the worst culprits was this "oh, look, we're in six levels of loop, ...
    (comp.lang.c)
  • Re: How do I best represent this operation in prolog
    ... clean up after b ... Or if you can accept Prolog's success and failure, ... Nick Wedd nick@xxxxxxxxxxxxx ...
    (comp.lang.prolog)
  • Re: Newbie fgets problem
    ... > fptr will always point to the file. ... without checking for success, then your code will misbehave on ... or test inside the loop and 'break' on failure. ...
    (comp.lang.c)
  • Hard Disk Not Mounting
    ... I want to port WinCE ... -USBD:OpenPipe success, hPipe = D039E210 ... HidParse: 'Preparing to Allocate memory ... DEVICQueuedPipe::CheckForDoneTransfers - failure on TD 0xd05858a0, ...
    (microsoft.public.windowsce.platbuilder)
  • Re: A simple parser
    ... success, EXIT_FAILURE for failure. ... indicate *success* to the calling environment. ... It's often possible to define return values other than the standard ... Other error codes could be syntax error in ...
    (comp.lang.c)