develooper Front page | perl.perl5.porters | Postings from June 2008

Re: Why $@ makes me cry

Thread Previous | Thread Next
From:
Aristotle Pagaltzis
Date:
June 27, 2008 07:01
Subject:
Re: Why $@ makes me cry
Message ID:
20080627140131.GD24815@klangraum.plasmasturm.org
* Paul Fenwick <pjf@perltraining.com.au> [2008-06-27 09:50]:
> I'm all for having eval/if work.

I didn’t say we should leave it alone. My point was fourfold:

1. Bugs that can be fixed should be fixed.
2. Not all of the problems of $@ admit bugfix-sized solutions.
3. Let’s not invent even bizarrer stuff in attempt to fix those.
4. But let’s do try to fix them.

I’d like to see as much as possible done to support the large and
here-to-stay legacy of `eval{};if($@){}`, but even more than that
I *really* don’t want it to become any harder to get exception
handling completely right, and I would like very much to see all
of the problems fixed thoroughly.

> $@ getting cleared as a side-effect of inspecting it doesn't
> bother me that much. It's something *obviously* going wrong. My
> big problem is with DESTROY/eval, where it's something sneakily
> going wrong.

See, it *does* bother me. The way exception handling works in
Perl requires *everyone* to be aware of *all* the gotchas and be
unfailingly cooperative *all of the time*.

Four words:

Good luck with that.

When a tool is that hard to use correctly, it’s time to consider
that maybe it is dangerous. Basically, people need to follow an
exception handling design pattern when they write `eval BLOCK` in
Perl; put it this way and then weigh MJD’s article on patterns[1]
against the issue and you’ll see where my stance comes from.

[1]: http://blog.plover.com/prog/design-patterns.html

And as near as I can tell, *all* of the nasty issues with $@ stem
from it being a global. So any mechanism to provide that value
without reliance on globals should resolve each and every issue
of `eval{};if($@){}` in one fell swoop. Once we had such a thing,
this entire class of errors would simply up and vanish, making it
more or less impossible for the programmer to get it wrong.

Is that not a worthwhile goal? Isn’t it even more so considering
how straightforward the essence of the solution is?

Regards,
-- 
Aristotle Pagaltzis // <http://plasmasturm.org/>

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