Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Journal of rob_au (1845)

Monday August 11, 2003
09:46 PM

Please, please, please

[ #14049 ]
For all that we love about Perl, please, please, please check return values when calling functions and object methods. And if writing such code, please incorporate differing return values based upon execution success.

/me returns to code maintenance and debugging

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • Fatal (Score:3, Interesting)

    by Juerd (1796) on 2003.08.12 3:21 (#23011) Homepage
    And in case anyone thinks "it's just a one-time hack" and "this is just a proof of concept" are valid excuses: no, they're not!

    If your code works, it will be used.

    Make sure that it provides enough information to fix the problem when it stops working.

    If you don't like checking return values (most of the time it's just a matter of adding "or die $!"), let something (or someone) do it for you.
    use Fatal qw(:void open close);
    open my $fh, $filename;
    ...
    close $fh;
  • Don't return undef (Score:3, Informative)

    by pdcawley (485) on 2003.08.12 6:36 (#23014) Homepage Journal
    Throw an exception. Any code I write for my own use is guaranteed to do one of three things:

    1. Return $self
    2. Return an 'interesting' value
    3. Throw an exception

    In general I'm slightly wary of object methods that return interesting values though, especially when those interesting values are simple attributes.