Syntactic Confectionery Delight | |
PerlMonks |
Re: A question about method return values and error checkingby thargas (Deacon) |
on Nov 04, 2015 at 19:10 UTC ( [id://1146932]=note: print w/replies, xml ) | Need Help?? |
My personal take on this is: it depends. If the thing to be returned is something which is supposed to exist, then I would throw an exception (die). If it's something which sometimes exists and sometimes doesn't, then undef is (IMHO) the way to go. So then, in this case, what should we do? Well, I'd say that an OS would be expected to have a name, so, lacking documentation to say whether undef is a valid thing to return, I would expect it to die. However, when we start to investigate further, there is no standard for how to determine such a thing as OS name, at least not portably, so I would accept the author's choice to return undef, as it seems, in the real world, this is indeed a piece of information which may be lacking. The best thing to do (IMHO) would be to provide a patch to the author which updates the docs to say that undef may be returned, and in addition, if it's about to return undef for name, try running "uname -o' and use that.
In Section
Seekers of Perl Wisdom
|
|