Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
One exit per procedure/function/codeblock to what purpos
Message
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00835552
Message ID:
00836114
Views:
21
>Hi Jim,
>
>SET SOAPBOX ON
>SET BAD MEMORIES ON
>
>
>I ***ABSOLUTELY SUBSCRIBE*** to the "one exit point" approach, and *ALL* my code follows this.
>
>Why? Simple answer -- because someone besides myself might have to read AND understand my code one day.

Hi Evan,

While I sympathize with you, I have to disagree IF you imply that a single exit point ALWAYS gives more readable code. If the programmer is forced to adhere to a 'single exit point' standard, then there will occasionally be many IF constructions, not only causing multiple indents, but also forcing the reader to browse to the ELSE section in order to understand what's happening. The reader/programmer will have to do a lot of page-browsing up and down, which will not improve understanding. One can only hope that the 'negative' condition (the condition that should directly lead to the door) is dealt with first in the IF and the positive condition is handles in the ELSE. Compare:
IF <value found>
   IF <some other value found>
      <real code>
      ...
      ...
      ...
      ...
      ...
   ELSE
      * quit this function
   ENDIF
ELSE
   * quit this function
ENDIF
IF <value not found>
   * quit this function
ELSE
   IF <some other value not found>
      * quit this function
   ELSE  
      <real code>
      ...
      ...
      ...
      ...
      ...
   ENDIF
ENDIF
There's another problem, valid for both examples. Suppose that 'value not found' should indeed directly lead to the door, the risk of coding like above is that in time this will not be the case. Another programmer might put some code at a place that breaks the direct path to the door, like in:
IF <value found>
   IF <some other value found>
      <real code>
      ...
      ...
      ...
      ...
      ...
   ELSE
      * quit this function
   ENDIF
   < code added by some other programmer >
ELSE
   * quit this function
ENDIF
Groet,
Peter de Valença

Constructive frustration is the breeding ground of genius.
If there’s no willingness to moderate for the sake of good debate, then I have no willingness to debate at all.
Let's develop superb standards that will end the holy wars.
"There are three types of people: Alphas and Betas", said the beta decisively.
If you find this message rude or offensive or stupid, please take a step away from the keyboard and try to think calmly about an eventual a possible alternative explanation of my message.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform