Re: When it will be freed?
- From: Richard Heathfield <rjh@xxxxxxxxxxxxxxx>
- Date: Tue, 20 Jan 2009 23:48:49 +0000
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
.
- Follow-Ups:
- Re: When it will be freed?
- From: Antoninus Twink
- Re: When it will be freed?
- References:
- When it will be freed?
- From: tfelb
- Re: When it will be freed?
- From: Joachim Schmitz
- Re: When it will be freed?
- From: jameskuyper
- Re: When it will be freed?
- From: jameskuyper
- Re: When it will be freed?
- From: jameskuyper
- Re: When it will be freed?
- From: Rafael
- Re: When it will be freed?
- From: Stephen Sprunk
- When it will be freed?
- Prev by Date: Re: Suggestions on improving program on binary tree postorder traversal
- Next by Date: Re: [POSIX & Win32API] Getting the 'routing' informations
- Previous by thread: Re: When it will be freed?
- Next by thread: Re: When it will be freed?
- Index(es):
Relevant Pages
|