Re: When it will be freed?



Stephen Sprunk said:

<snip>

While there are some advantages to having a single return point,
more pragmatic programmers believe that complex code is often
easier to understand with multiple return (or exit()) points.

Whilst I naturally accept that your opinion differs from mine (for I
am one of those who prefers a single exit point), my opinion - like
yours - is based on pragmatism.

I vaguely recall an anecdote about a couple of engineering students
who were sharing a house. Each devoted a perhaps unwarranted amount
of time to considering the question of whether it was more
practical to hang toilet rolls with the dangling end on the wall
side or the room side. Each felt that he had approached the problem
objectively, rationally, and logically, with pragmatism being the
sole criterion. And of course they arrived at opposite answers.

My basis for preferring a single exit point is twofold: firstly, it
tends to require the programmer to think carefully about the
logical structure of the function; and secondly, when I'm
maintaining other people's code I invariably find single exit point
code easier to grok than multiple exit point code. Clearly that's a
matter of opinion/style, though.

This is not
unlike the debate about "goto"; avoiding it is a good idea in
general, but there are times it's the best tool for the job.

I liked a sig I saw recently about goto - something like "I tell my
students not to use goto, but I use it myself. I use a revolver,
too, but I don't give it to my children." Personally I don't use
goto at all, but in theory I am prepared to use it if I consider it
the best solution to a problem. In practice, however, when I am
actually writing the code, it never occurs to me to think about
whether it might be the best solution. I don't think I've ever used
goto in C programming, unless it was for expository reasons. (I
used to use it in BASIC programming all the time, but that was in
an ancient dialect whose only structured constructs were FOR/NEXT
and IF...THEN GOTO... - and even that usage stopped when I
discovered subroutines.)

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
.



Relevant Pages

  • Re: When it will be freed?
    ... Some programmers do not like the idea of multiple return points from a function; they want all code paths to reach a single return point at the end of the function. ... While there are some advantages to having a single return point, more pragmatic programmers believe that complex code is often easier to understand with multiple return (or exit()) points. ... This is not unlike the debate about "goto"; avoiding it is a good idea in general, but there are times it's the best tool for the job. ...
    (comp.lang.c)
  • Re: Infinite Loops and Explicit Exits
    ... a method of evaluation which enabled people knowledgeable about film, ... While both programming and movies are evolutionary, ... The only compiler that has EXIT PERFORM in out-of-line in Chuck's ... > END-IF ...
    (comp.lang.cobol)
  • Re: When it will be freed?
    ... pragmatic programmers believe that complex code is often easier to ... understand with multiple return (or exit()) points. ... unlike the debate about "goto"; avoiding it is a good idea in general, ...
    (comp.lang.c)
  • Re: goto
    ... > non-zero if the exit is needed. ... >>However I haven't used goto since some time back in school, ... imposing such restrictive rules will be able to protect bad programmers from bad programming). ... I can understand the use of goto for the situations that I described. ...
    (comp.lang.cpp)
  • Re: Idiom wanted: do-while
    ... structured programming definition -- every block of code has one entry point ... Break statements clearly violate the "one exit point" ... most not being privy to original design considerations, ...
    (comp.lang.ruby)