On Jun 27, 2006, at 3:11 AM, Michael Hawksworth wrote:

The single vs multiple point of exit argument has been going on for years, made more intense by the arrival of the newer development theories.

That arose in the days of 'top-down' programming, which was all the rage when I was in college. When you wrote your code, you created pseudo-code where you defined your procedures and their return values, and then you fleshed out the actual code that produced those return values. Probably the biggest reason for insisting on the "one entry, one exit" style was the prevalence then of GOTO, which was abused terribly; this style was a reaction to that 'anything goes' style and its spaghetti code results.

Personally, I think that what's important is predictable, readable code. The one exit style is just an attempt at achieving this. But having a style that checks for conditions at the top of a procedure and exits if they are not met is a very clear, readable and maintainable style. In fact, most main methods in Dabo follow the pattern I added to Codebook methods:

def doSomething(self):
        errorCode = self.beforeDoSomething()
        if errorCode:
                return errorCode
        <main code goes here>
        self.afterDoSomething()
        return resultCode

IOW, every X method has a built-in test: beforeX(), and returning an error code from that will prevent the rest of the method from running. Sure, I could have structured it with only one return, but I don't believe that the code would be better or more readable if I did./

-- Ed Leafe
-- http://leafe.com
-- http://dabodev.com





_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/profox
OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech
** All postings, unless explicitly stated otherwise, are the opinions of the 
author, and do not constitute legal or medical advice. This statement is added 
to the messages for those lawyers who are too stupid to see the obvious.

Reply via email to