Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
VFP Bug, who's seen it?
Message
From
16/12/1999 15:54:41
 
 
To
16/12/1999 15:30:34
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00304389
Message ID:
00304859
Views:
33
>Hi Guys,
>
>>>>Sounds like a good reason to only have 1 RETURN, at the bottom
>>>>of the routine.
>
>Just an FYI: I read an article by JimB along the lines of "Take the Slow Parts Out", and he mentioned returning early is usually faster than an IF to bypass all the code until the end of the routine. IAC, I don't have a religous preference, just whatever works well at the time.
>

This is one oft touted convention that I don't stick to at all.

Say I have a routine that has to check for several conditions before it can get to the meat of the routine, if any of them fail, it should return .F. instead of running through. If I stick tothe convention that the routine should only exit in one spot, I have to write code that looks like
llAllPass = .T.
IF !SomeCondition
	llAlPass = llAllPass AND .F.
ENDIF
IF !SomeOtherCondition
	llAlPass = llAllPass AND .F.
ENDIF

And then the rest of the operation code has to be wrapped in IF llAllPassed

Seems much easier and cleaner to me to just 

IF !SomeCondition
	RETURN .F.
ENDIF
Erik Moore
Clientelligence
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform