Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Cool idea for SET commands
Message
From
27/07/2004 14:14:55
Walter Meester
HoogkarspelNetherlands
 
 
To
27/07/2004 09:23:21
Mike Yearwood
Toronto, Ontario, Canada
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00928029
Message ID:
00928408
Views:
66
Hi mike,

I´m one that tries to avoid multiple exits point as much as possible. One of the big motivations I find is that it generally produces more readable code and avoids issues with resetting the environment, whether or not using a clever class handling settings. Restoring settings is only one of the many things you might want to reset at the exit point. For example form properties are not that easy to handle. For example when a piece of code handles a lot of GUI changes, you might want to use Lockscreen to block the GUI updates until you´re done. Now this is a nasty one if you forget to reset it to false when you exit a procedure.
LPARAMETERS cVar
LOCAL lRet, cSafety

IF VARTYPE(cVar) = "C"
   cSafety = SET("SAFETY")
   SET SAFETY OFF
   
   * Some buisiness processing

   lRet = SomeBusinessCondition AND DoSomething()

   SET SAFETY &lcSafety.
ENDIF
RETURN lRet
or with the use of the pushup class
LPARAMETERS cVar
LOCAL lRet, oSafety

IF VARTYPE(cVar) = "C"
   oSafety = CreateObject("PushPop","SAFETY","OFF")
   
   * Some buisiness processing

   lRet = SomeBusinessCondition AND DoSomething()
ENDIF
RETURN lRet
Personally (Yes I agree some might beg to differ) I find this much more readable than your example where the procedure can be exited at three different point.

Walter,



>
LPARAMETERS m.tcVar
>IF VARTYPE(m.tcVar) # "C"
>  RETURN .F.
>ENDIF
>LOCAL m.lcSafety
>m.lcSafety = SET("SAFETY")
>SET SAFETY OFF
>* ... some processing
>IF somebusinesscondition = .F.
>  SET SAFETY &lcSafety. && You have to remember to reset it here.
>  RETURN .F.
>ENDIF
>DO SOMETHING
>SET SAFETY &lcSafety.
>RETURN
>
>********************
>
LPARAMETERS m.tcVar
>IF VARTYPE(m.tcVar)#"C"
>  RETURN .F.
>ENDIF
>LOCAL m.loSafety
>m.loSafety = CreateObject("PushPop","SAFETY","OFF")
>* ... some processing
>IF somebusinesscondition = .F.
>  RETURN .F. && The pushpop class will reset here.
>ENDIF
>DO SOMETHING
>RETURN && The pushpop class will reset here.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform