Re: Function return value

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance




"Jay Freedman" <jay.freedman@xxxxxxxxxxx> wrote in message news:%23avUR%23suFHA.2212@xxxxxxxxxxxxxxxxxxxxxxx
The technical answer is, it *can* be done in several places; that is,
example 1 will work.

The answer from experience is, it *should* be done only in one place, for a
couple of reasons. The main reason is to help prevent bugs, or to ease
debugging when the inevitable happens. This goes together with the general
rule that, except for error-handling, there should be only one exit point
for each sub/function.

Personally, I take a more relaxed view of this. I think that Example 1 is perfectly good code, and reduces the amount of jumping about within a routine and reduces the total number of lines of code.


There are cases where a single exit point would be advisable, such as where there is a need to restore global parameters (such as the position of the Selection) prior to exit. These issues need to be addressed on a case-by-case basis.


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org


.



Relevant Pages

  • Re: SYS$STARTUP:MMOV$SHUTDOWN.COM -- Insufficiently discriminating?
    ... > I've lost track of the reasons, ... I see a simmilar behaviour on my cluster. ... to exit their own building the call died. ...
    (comp.os.vms)
  • Re: Re: New http attack?
    ... ('binary' encoding is not supported, ... have hidden IP for obvious reasons. ... I managed to download the file myself manually, and submitted to symantec, as my virus checker didnt flag it. ...
    (Incidents)
  • Re: catching exit
    ... reuse it as a library. ... AFAIK there is no portable way to catch the exit. ... think of big chunks being made up of little chunks, ... But I have my reasons, ...
    (comp.lang.c)
  • Re: exit, atexit and scope
    ... >> same functions that exit() does it certainly would be. ... "For the execution of a function registered with atexit(), ... leaves the function because it provides no handler for a thrown ... implementations may follow it for the same reasons. ...
    (comp.lang.c)
  • Re: What is the difference is the placement of wait() here
    ... macros WIFEXITEDand WEXITSTATUS() since the status value you ... get from waitis a combination of the process' exit status ... and some more information about the reasons the process exited. ...
    (comp.unix.programmer)