develooper Front page | perl.perl5.porters | Postings from November 2000

Re: Plan to try again with Carp

Thread Previous | Thread Next
From:
Ben Tilly
Date:
November 26, 2000 10:46
Subject:
Re: Plan to try again with Carp
Message ID:
LAW2-F160VrDs9aAOPp00003882@hotmail.com
Hugo wrote:
>
>In <LAW2-F99Wr81nn9RQAO00003271@hotmail.com>, "Ben Tilly" writes:
>:Feedback?  Comments?
>
>It isn't clear to me why you want to kill $Carp::CarpLevel, though
>I read your email through a couple of times to try and understand
>this. I regularly use the moral equivalent of:
>   local $Carp::CarpLevel = $Carp::CarpLevel + 1;
>.. in diagnostic functions.

Well there are two places that it exists.  I think that
both are bad.  First of all for short messages it
results in simply confusing behaviour:

########################################################
package A;
@ISA = qw(B);
sub Error { B::Error() }

package B;
sub Error { C::Error() }

package C;
@ISA = qw(D);
sub Error { D::Error() }

package D;
use Carp;
sub Error {
    $Carp::CarpLevel = 1;
    croak("Something bad");
}

package main;
# Good luck figuring this one out from the source.
# The half-way correct comments don't help much either.
# line 1 "Why here?"
A::Error();
########################################################

I fail (to put it mildly) to understand how this "feature"
is supposed to improve debugging.  Yet this is *EXACTLY*
what warnings.pm attempts to use (without actually
understanding what the feature is for) despite it being
completely broken in principle.  Exporter tried to use it
likewise, resulting in some very confusing debugging
messages.  (At a glance is still trying to use it, and is
getting it wrong!)

The other place it shows up is in long messages.  There
it actually does do something moderately useful.  It
edits call levels out.  If (as a debugger might) you
have kept track of call levels, then you can use it to
edit yourself out of the messages.  Now suppose that
you want to guarantee that Exporter is supposed to
not show up if someone sets $Carp::Verbose to a true
value.  Now you have to go through how much work to
figure out the correct $Carp::CarpLevel to set?

Since that is apparently the point of having it, I would
prefer to set up a simpler API to get that effect.

>I've also never particularly understood why it wasn't documented.

Perhaps because it was known by the original author
to be a hack which they wanted to only be used by
stuff internal to Perl.  I note that the original
version was a heuristic.  It didn't quite have any
easily describable behaviour, but it was often enough
right to be useful.  The exact effect of setting
$Carp::CarpLevel was (and remains) not easily
describable, and is highly specific to the
implementation.  Therefore there was no easy way
to document it, and indeed it should have been
changed.

What should not have happened is what did.  Which is
that people would come to misunderstand what it does
and start using it based on that misunderstanding.
Since it has been misunderstood, and it has never
been documented, I think it should be broken and
replaced with a better API which leaves more room for
the internal code to be rewritten.  (Say without the
need for gratuitous gotos?)

If people think that I am being too extreme, then
please tell me what behaviour you think it should
have and we can implement that.  But I will be
shocked and amazed if people can some up with good
a priori reasons why the current behaviour makes
sense or is maintainable.  Certainly the places where
I have seen people try to use it have usually led to
bugs!

Does that explain my opinion?

Cheers,
Ben
_____________________________________________________________________________________
Get more from the Web.  FREE MSN Explorer download : http://explorer.msn.com


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About