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

...I've never liked the output from Carp. Ever. The stacktrace is humungous, hard to navigate, and very rarely provides anything useful (to me).

I know what you mean about stack traces being big, noisy, pointless things -- and I totally agree. But it may be that the uses I've seen and had for carp/croak haven't been so "deep" that their output has been a problem for me.

On the contrary, I've been really grateful for all the times where a given method or function from a module is being used in a lot of different places in an app that I'm working on, and when I make a mistake, carp or croak tells me which line number in calling code triggered it -- without a whole lot of other useless trivia (all the args passed at every layer of the call stack, what their memory addresses were, what the command-line looks like as hex bytes, blah blah blah...)

(My colleagues who use python don't seem care much about error reports -- every time one of their python scripts hits a dead-end, the user gets several lines of doggerel with seemingly random white-space/line-breaks and rarely a legible word, let alone a coherent phrase. Even for cases where the user just needs to be told "file foobar not found". I don't understand why anyone would want or allow errors to be handled in such a way. But I generally don't see this sort of thing with perl code using carp or croak.)

If you feel that users of your module are very unlikely to call a given method or function from more than one spot in their apps, don't worry about it. But if it's likely that one app might use a given sub in lots of different places, you'll probably be doing the module user a very big favor by telling which line in the caller's code caused a given problem.

  • Comment on Re: Replacing warn/die with carp/croak?

Replies are listed 'Best First'.
Re^2: Replacing warn/die with carp/croak?
by simul (Novice) on Nov 16, 2009 at 08:31 UTC
    Simplest thing to do is go on using die and warn. Then if someone, perhaps you, wants more info, they can "use diagnostics". It's really much easier that going through your code and replacing everything. It's also more efficient... since the Carp (or diag) module need not be loaded unless there's a problem.

    Many module authors have taken to "require Carp" just before croaking.... to alleviate this... which is a cumsy but effective solution.

    I really think "use diagnostics" or perl -Mdiagnostics=-traceonly has replaced the need for carp/croak. If you need to be verbose ... you can get it as needed.