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 18:30:53
Mike Yearwood
Toronto, Ontario, Canada
 
 
To
06/10/2003 17:21:50
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00835552
Message ID:
00835572
Views:
22
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
Next
Reply
Map
View

Click here to load this message in the networking platform