Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
One exit per procedure/function/codeblock to what purpos
Message
De
08/10/2003 06:10:47
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
08/10/2003 06:02:01
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
00835552
Message ID:
00836115
Vues:
20
>>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
Peter,
Strongly agree. I too doesn't follow the 'one exit point' rule or even don't accept it as a rule but as pure preference.
From readability point I find it much easier to follow code that has 'early' returns :)
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform