Yes! there is great value a simple statement:
A function/method/sub should have one entry and one exit
If you uphold to this adage then your code will be more versitile, it is a damn site easier to add to subs that exit in a standard controlled way. The other problem is that in any meduium to large scale application you dont have enuff information to give a good message to the user only the calling sub has the context that your error messages need. What is the use of die'ing with a cant open file bob, if you dont tell the user why you wanted to open the file where it should be and what (s)he should do about it. Even if your code is simple the effort will bring reward if you ever try to add / build on that simple app (as functionality creaps).
Having said all that just to contradict myself for a moment. I do use die for situations that catagorically cannot happen (just to be sure that if they do I will get to know at source) if ever my programs call die from within a sub I do regard it as a bug to be fixed because it means that something that cannot happen just did ;-).
--
Zigster
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.