[Tutor] Multiple exits in a function...

Mike Hansen mhansen at cso.atmel.com
Fri Oct 24 10:28:30 EDT 2003


I'm curious about this. A co-worker was ranting recently while debugging 
some C code that it had multiple exits. (BTW: It wasn't my C code. I 
have never written C code except in college.)

I trend to write my functions with multiple exits. Usually when some 
test fails, I spit a message(email, print it, or write it to a log file) 
and get out of dodge. The alternative is usually horrible nested If 
statements even if I flip the logic around. Which to me makes it hard to 
read and maintain.

Can you point me to some resources to help me wrap my mind around this? 
Code examples? ...

Thanks,

Mike

>
> Subject:
> Re: [Tutor] Re: Request for code critique ['break' vs control flag]
> From:
> "Alan Gauld" <alan.gauld at blueyonder.co.uk>
> Date:
> Thu, 23 Oct 2003 06:00:22 +0100
> To:
> "Danny Yoo" <dyoo at hkn.eecs.berkeley.edu>
>
>
>>>whence into many other languages) which breaks the rules of
>>>      
>>>
>structured
>  
>
>>>programming and by so doing makes code more difficult to read
>>>      
>>>
>reliably.
>
>  
>
>>But I've also met a lot of respected programmers who insist on the
>>    
>>
>"one
>  
>
>>entry point, and one exit point" viewpoint. 'break' drives them
>>    
>>
>crazy.
>  
>
>>So, like many style guidelines, it's a controversial issue. *grin*
>>    
>>
>
>I think the issue is that this is NOT a style thing. It's
>one of the basic tenets of structured programming and based
>on actual hard data. Having multiple exit points makes code
>harder to comprehend and hence more prone to error.
>
>Sometimes people forget the reasons behind some of these
>early discoveries in Computer Science. In fact I just finished
>reviewing a book by Robert Glass: "Facts and Fallacies of
>Software Engineering" which is based entirely on the concept
>that the faddy world of SE regularly forgets (and subsequently
>rediscovers) some of the basic truths of our trade...
>
>It falls into the same category as indentation style for
>begin/end or {} block markers. People treat it as a personal
>choice but hard evidence exists which shows that some styles
>are significantly more comprehensible than others.
>
>Alan G.
>
>  
>
>




More information about the Tutor mailing list