When using procedural languages, I usually try to maintain a single exit from a procedure. I have had several occassions where I had to add some cleanup code at the end of a procedure. Since the procedure had multiple exits, I had to do some searching to find all of them and then rework the code so it would all fall off the end. On the other hand, I'm not a purist -- if the code starts getting too twisted in order to pull this off, I'll use additional returns or (gasp!) a goto.
Lately, though, I've been working more with object oriented languages than with procedural languages where this has been less of a concern. Most of the things that would need cleaning up get handled automatically by destructors of objects going out of scope. In case of errors, I'm probably using a throw instead of a return, though.
In perl, a common exit can easily be implemented with a naked block inside the routine. Use last instead of return inside the block and have all cleanup code following the block. I've seen similar things done in C with a do { ... } while 0;.
--- print map { my ($m)=1<<hex($_)&11?' ':''; $m.=substr('AHJPacehklnorstu',hex($_),1) } split //,'2fde0abe76c36c914586c';
In reply to Re: Re: A matter of style
by pfaut
in thread A matter of style
by Ryszard
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |