in reply to Replacing warn/die with carp/croak?

I like the less convoluted and most flexible solution. I use Carp::cluck and Carp::confess a lot during development, switching later to warn and die.

There are cases in which croak reports wrong line numbers. I generally prefer modules which use just warn and don't die, because die in a module leads to evalitis.

I would rather see warn in modules, because I can override that easily with a $SIG{__WARN__} = \&Carp::cluck, and don't have to redefine Carp::croak.

I have stumbled over a very nasty usage of croak in the IO::All module, which wraps croak into a function called throw(). Took me some time wondering, and searching through the module to find out why my __DIE__ handler didn't work. I ended up redefining IO::All::throw with a custom function.

So, I wouldn't make the change, but answer to the ticket issuer "You can always install your custom handlers via $SIG{__WARN__} and $SIG{__DIE__}" and leave it there.

--shmem

_($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                              /\_¯/(q    /
----------------------------  \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}

Replies are listed 'Best First'.
Re^2: Replacing warn/die with carp/croak?
by dragonchild (Archbishop) on Oct 04, 2007 at 14:50 UTC
    Forcing usage of $SIG{__WARN__/__DIE__} sounds poor. However, does it make sense to provide an option for using carp/croak vs. cluck/confess vs warn/die ?

    My criteria for good software:
    1. Does it work?
    2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?
      Sounds poor? Well, those pseudo signals exist for that purpose.

      A verbosity switch makes sense, imho.

      --shmem

      _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                    /\_¯/(q    /
      ----------------------------  \__(m.====·.(_("always off the crowd"))."·
      ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
Re^2: Replacing warn/die with carp/croak?
by fenLisesi (Priest) on Oct 05, 2007 at 08:45 UTC
    Evalitis [ee-vuh-lie-tis]: Sounds like a disease, but actually a good thing. Also see: suffrage. DISCUSSION: Don't be afraid to die (or croak). Let them eval you. That will lead to more maintainable code. </word-of-wisdom-from-fenLisesi-the-quack>
      Let them eval you. That will lead to more maintainable code.

      A bold statement. Please expand your reasoning - why would them having to eval me make their code more maintainable? or mine, for that matter?

      --shmem

      _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                    /\_¯/(q    /
      ----------------------------  \__(m.====·.(_("always off the crowd"))."·
      ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
        Man, I was trying to avoid the grand-statement effect by calling myself a quack, truly yours, but you called it. OK, well, I think being death prone helps:
        • the module author by making the module code simpler
        • the user in the long term by forcing him to be explicit about what he wants to do with the errors
        • the user's user by making it likelier that the user will provide his own error messages, which will probably make more sense to the user's user.

        I am here to learn, though, not teach, which I couldn't even if I wanted to, so I am eager to hear your response, shmem, and those of other wise monks. Cheers.