Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
VFP Bug, who's seen it?
Message
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00304389
Message ID:
00304858
Views:
36
>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.

First, and foremost, if JimB says it, it's my experience that it's usually gold, so you can take it to the bank. However, I'd contend that just because it's faster, doesn't necessarily mean you should do it. If performance isn't an issue with the code, then don't, because you ultimately do harm to the readability. I've always maintained that, "If it ain't readable, it ain't maintainable." Further, I realize that I'll spend more time in maintenance and modification (updates, etc.) than anywhere else.

Let me give you an example of this. We all know that FOR...ENDFOR/NEXT is faster than a DO WHILE...ENDDO incrementing some sort of counter. However, if the possibility exists for premature exit (you don't go from 1 to < n > iterations), then the latter is preferable, because that's what it's designed for. However, many people think, "Well, since the FOR is faster, I'll use that". The problem here is that you harm readability with the EXIT (which is conditional, to boot), plus you have to literally get into the 100,000s of iterations before you realize a gain of as much as a 1/10th of a second. Bruce Campbell and I went over this a couple of years ago with some tests that came about from an exchange on this.

I guess what I'm saying is that if there is no noticable (to the user) difference, then don't use this sort of technique. Both the early return and the premature loop issues go against what's generally accepted as good technique. Are there times to "break the rules"? Certainly, but we need to be care and quantify the reason for doing so, rather than a knee jerk, "This is faster".

>Oh, Look at all the new things you miss when I turn the graphics off :-) Cool Picture Erik!

How 'bout dat?
George

Ubi caritas et amor, deus ibi est
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform