in reply to Programming style question on where to use die

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
  • Comment on Re: Programming style question on where to use die