Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Short-Circuiting with Logical Operators
Message
De
03/11/2014 14:55:20
 
 
À
28/10/2014 08:46:27
Dragan Nedeljkovich (En ligne)
Now officially retired
Zrenjanin, Serbia
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 9 SP1
OS:
Windows Server 2003
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01609995
Message ID:
01610415
Vues:
81
>Whoever needs the reminder... it's been drilled into me that any compiler will shortcircuit your logicals, period. And I take that into account whenever I'm coding. I've seen a few experienced guys do things like this

VB being the most prominent exception.

>
>
do case
>   case not .FirstProcessGoesWell()
>   case not .SecondProcessGoesWell()
>...
>   case not .LastProcessGoesWell()
>   otherwise
>      oMsg.Message("all is well")
>endcase
>...which is, for me, perhaps the neatest packaging of multiphase batch process, which needs to be abandoned on first critical error. Can't remember whom I first saw doing this, perhaps the Feltmans or someone around the ComCodebook project. This is shortcircuiting by design.

I do that mostly for debug ease - and remember seeing it in non-visual foxpro

>
>However, I've found a case where I'd expect shortcircuiting to work, but it doesn't. It's the evl() and nvl() functions, where both parameters are evaluated, regardless of what the first one returns. So if you try
>
>xx=evl(call1(), call2())
>
>call2 will be called no matter what call1 does. This is kind of counterintuitive, because the equivalent construct with iif() will not have this side effect.

Probably a function of being a function: these are parameters and parameters are calculated before entering the functions body.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform