Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Cool idea for SET commands
Message
De
27/07/2004 11:43:31
Mike Yearwood
Toronto, Ontario, Canada
 
 
À
27/07/2004 10:04:05
Dragan Nedeljkovich (En ligne)
Now officially retired
Zrenjanin, Serbia
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00928029
Message ID:
00928338
Vues:
54
Hi Dragan

>While I agree that the cSet class (which exists as a freebie in the CodeBook, and is inherited in at least one CodeBook-derived framework that I used) makes things simple, your example of an early exit is slightly wrong - the exit is not early enough. If you're exiting early, you should do so before you change any SETtings:
>
>
LPARAMETERS m.tcVar
>IF VARTYPE(m.tcVar) # "C"
>  RETURN .F.
>ENDIF
>IF not somebusinesscondition
>  RETURN .F.
>ENDIF
>* now we're doing business, save settings and do it
>LOCAL m.lcSafety
>m.lcSafety = SET("SAFETY")
>SET SAFETY OFF
>* ... some processing
>DO SOMETHING
>* ...done, restore.
>SET SAFETY &lcSafety.
>RETURN
>
>Of course, there may be other exits that may be required during the business part, but these may be bracketed using a simple status variable:
>
lOK=SomeCheck()
>if lOK
>   * do some more
>   lOK={new check condition}
>endif
>
>if lOK
>   * keep on processing
>   lOK={another check condition}
>endif
>* done, restore
>
>This way you don't have to have other exits but the early exits (before you disturb the settings) and one final exit (where you restore the settings).

That's just one way to do it. You may not always be able to exit before the settings have been changed. IMO the lOK scattered through the block of code makes it harder to follow the logic. I find things much easier to follow if they exit as soon as processing cannot continue. But the point I was trying to make is we have more freedom to decide how to code things with these classes protecting us from ourselves.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform