Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
One exit per procedure/function/codeblock to what purpos
Message
From
06/10/2003 20:27:58
 
 
To
06/10/2003 18:30:53
Mike Yearwood
Toronto, Ontario, Canada
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00835552
Message ID:
00835590
Views:
18
Hi Mike,

Your last 2 samples clearly illustrate what I'm getting at.

Now add to that a routine of some complexity that might also have some conditions later that mandate an early return, either because some expected record or combinations of (record/memvar) codes obviate the additional processing or because a called function returned a negative or..... What is the value of setting llReturn =.F. and then having several more "IF llReturn" s before all following decision/action points?
Isn't a simple
DO CleanUp
RETURN .F.
both far more INFORMATIVE and much clearer too, not to mention the reduction of complexity (extra "IF llReturn/ENDIF"s that can only help to confuse a reader?

cheers

>Hey Jim
>
>I don't follow that practice. I believe that practice served a real purpose at one time. If I have to execute some code, to have it remember and reset certain settings I'd want to do that if the routine worked or not.
>
>
PRIVATE pcSetTalk
>pcSetTalk = SET("TALK")
>
>SET TALK ON
>
>IF Condition
>  REPLACE FIELD WITH VALUE IN TABLE FOR CONDITION
>ELSE
>  REPLACE FIELD WITH VALUE IN TABLE FOR OTHERCONDITION
>ENDIF
>
>SET TALK &pcSetTalk
>
>RETURN
>
>If I returned inside the IF, I'd never get the SET TALK back to the previous setting, or I'd have to remember to set it when I returned.
>
>Another option would be to ...
>
>
PRIVATE pcSetTalk
>pcSetTalk = SET("TALK")
>
>SET TALK ON
>
>IF Condition
>  REPLACE FIELD WITH VALUE IN TABLE FOR CONDITION
>  RETURN CLEANUP()
>ELSE
>  REPLACE FIELD WITH VALUE IN TABLE FOR OTHERCONDITION
>ENDIF
>
>DO SOMETHINGELSE
>
>RETURN CLEANUP()
>
>FUNCTION CLEANUP
>  SET TALK &pcSetTalk
>ENDFUNC
>
>
>Here's what I do.
>
>We could write code like this but what is the benefit?
>
>
>LOCAL llOK
>IF VARTYPE(m.tcParm1)="C"
>  IF SOMETHING
>    LOCAL m.loSetTalk
>    m.loSetTalk = CreateObject("SETTALK")
>
>    SET TALK ON
>    REPLACE FIELD WITH "VALUE" FOR Condition = .T.
>    RELEASE m.loSetTalk
>    m.llOK = .T.
>  ELSE
>    llOK = .F.
>  ENDIF
>ENDIF
>RETURN m.llOK
>
>
>Anything known to cause a failure will be handled right up front. This leaves the meat of the problem clearer.
>
>I'd agree with this as a standard.
>
>
LPARAMETERS tcParm1
>IF VARTYPE(m.tcParm1)#"C"
>  RETURN .F.
>ENDIF
>
>IF NOT SOMETHING
>  RETURN .F.
>ENDIF
>
>LOCAL llOK
>llOK = .T.
>
>LOCAL m.loSetTalk
>m.loSetTalk = CreateObject("SETTALK")
>
>SET TALK ON
>REPLACE FIELD WITH "VALUE" FOR Condition = .T.
>RELEASE m.loSetTalk
>RETURN m.llOK
>
>
>
>>Continuing PeterDeV's quest towards a set of 'excellent coding standards'...
>>
>>What is the value/purpose of "one exit point per code unit?"
>>
>>Isn't it time that this old chestnut was retired?
>>
>>I don't see an iota of **real** value to the practise, but I do see problems.
>>
>>Why do you follow the practise?... if you don't, why don't you and what static have you heard from others about it?
>>
>>Anticipating interesting replies,
>>JimN
Previous
Reply
Map
View

Click here to load this message in the networking platform