Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^2: Returning undef: The point I would like Damian to reconsider

by martin (Friar)
on Jun 22, 2007 at 19:59 UTC ( [id://622899]=note: print w/replies, xml ) Need Help??


in reply to Re: Returning undef: The point I would like Damian to reconsider
in thread Returning undef: The point I would like Damian to reconsider

I think the truly "best" practice would be to use an exception class hierarchy and throw exceptions upon errors. I <3 Exception::Class
Agreed, but that was not the point of this guideline. To be fair to TheDamian, he dedicated a whole chapter to error handling, where among other things he discusses exception hierarchies in depth.

Damian's point in this guideline was, one should use an empty return statement where returning undef could lead to unexpected results, while my main point was that he failed to properly distinguish that exotic case from good uses of returning undef, seeing that now some programmers think it should be avoided altogether.

Personally, I prefer to use empty return statements only for void context, i.e. subroutines or methods that don't offer a return value. If I found myself catering for context-aware return value polymorphism I would not mind to use a more explicit construct.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://622899]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (2)
As of 2024-04-24 23:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found