Paul Johnson wrote: > Rob Dixon said: > > "Rob Richardson" <[EMAIL PROTECTED]> wrote in message > > news:[EMAIL PROTECTED] > > > Stefan, > > > > > > Personally, I'd prefer: > > > > > > if (target ne "MAIN") > > > { > > > #do lots of other stuff > > > } > > > > > > I think general programming practice discourages multiple return points > > > in subroutines. > > > > Yes, and it's no more dangerous than multiple 'last' statements in loops. > > To my mind, > return if $target eq "MAIN"; > at the top of a sub is a lot more helpful than making me search all the > way down to the botttom to see if there is anything after the conditional. > > And it's probably a lot less likely that the next person to edit that sub > will goof up by adding something where it shouldn't be. > > Slavish devotion to the single exit point paradigm can produce some > wonderfully messy code, all scrunched up at the right of the screen.
It's one of the more useless dogma to have come out of the industry. As you say it's easy to create unreadable code through being tied to only a single 'return', and I'd say it's just about as easy to write nonsense by scattering returns through a subroutine with impunity. Any rule to get around the problem has to be much less simplistic. It's the same problem as the anti 'goto' camp. I would say that gotos are fine, but labels are a real problem because you can use them to jump into and out of scopes and pop stack frames as you wish. 'next', 'last', 'redo', 'return', 'exit' and subroutine calls are all gotos, except that they're not allowed labels in the general sense that 'goto' is. The point they refer to is a well defined and sensible place to pass control to within normal programming practice. > Then again, I probably wouldn't merge those two original lines either. That's another one for another day :) Cheers, Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]