|
|
|
Your skill will accomplish what the force of many cannot |
|
| PerlMonks |
Re^8: STDERR in Test Resultsby bliako (Abbot) |
| on Jul 17, 2023 at 21:59 UTC ( [id://11153453]=note: print w/replies, xml ) | Need Help?? |
|
I don't like dieing at any point in my programs and I look down on code which does that and forces me to try/catch/eval each of its calls instead of checking the error code that each function, IMO, should return (with reasonable exceptions of course). I avoided to express my opinions as I respect the particular opinion of those particular Monks who were in favour of die as error signaling and decided to keep quiet and contemplate on their points and see if I can change my opinion. Well, I haven't mainly because of reasons of style. I still return error codes or error hashes with code+message. I started with C, and it shows, and I think I will die with C. But! I found a compromise: I now consider a die to be an exception (as in, e.g. C++/Java) and it does not look as the "nutter's nuclear option" as it did. And I may even experiment dieing with an Exception object (read on before telling me that that's possible already :)):
But at that exact point of my epiphany I learned that die can throw ANYTHING (about time!), so:
So, yes, I can view die as an exception and am prepared not to consider it antisocial, from now on. The only problem remaining is performance:
No contest there for no_die. But the test may be misleading because no_die() needs constant return status checking with an if exists. Whereas, as you show in the transactions example you provided, functions which die can skipp the individual checking and enclose them all in one big try{}catch{} block. Which is probably way faster. And I don't know which looks uglier: huge try{}catch{} blocks or endless if func() then else (actually I think the latter). So, thanks for the food for thought you provided. I am much more inclined in using die now in subs especially the dieing with custom-made exception objects. bw, bliako
In Section
Seekers of Perl Wisdom
|
|
||||||||||||||||||||||||||||||