From: Alex Young Date: 2007-10-20T18:56:20+09:00 Subject: Re: Is it always the norm to skip 'return'? Arlen Christian Mart Cuss wrote: > On Sat, 2007-10-20 at 09:23 +0900, Pat Maddox wrote: >> You're doing great up until >> >>> but even that is considered bad programming practice (functions should have >>> only one exit). >> which is just ridiculous. > > I concur. There's nowhere that says that functions should have just one > exit - it doesn't necessarily make for bad style, or code noise. http://www.research.att.com/~bs/JSF-AV-rules.pdf, section 4.13.2, Return Types and Values: "AV Rule 113 (MISRA Rule 82, Revised) Functions will have a single exit point. Rationale: Numerous exit points tend to produce functions that are both difficult to understand and analyze. Exception: A single exit is not required if such a structure would obscure or otherwise significantly complicate (such as the introduction of additional variables) a function�s control logic. Note that the usual resource clean-up must be managed at all exit points." This is from a (heavily referenced) C++ style guide, specifically for code written for the Joint Strike Fighter. I'm no C++ expert, but I'm led to believe that having more than one exit point in a function in C++ can lead to resource release problems. As such, it would have a clear, practical effect there. Also, C++ functions tend to be longer (in pure LOCs) than Ruby methods, so structural complexity is more of a barrier to comprehension. If you google for "single-entry, single-exit" you'll find more references to this style and where it comes from - typically high-reliability embedded system design, as far as I can tell. It's less of a problem in Ruby, I think, mainly because of the expressiveness and the presence of GC. -- Alex