http://qs1969.pair.com?node_id=863493


in reply to Re^8: eval to replace die?
in thread eval to replace die?

Just one example is that isa() knows how to look up the inheritance tree

Actually the built-in isa() only checks one level. UNIVERSAL::isa() does a hierarchy traversal--which is a hash lookup. And a hash lookup is just a string compare at it's heart.

But if you're using eval & die you don't need isa, so the point (in context) is moot.

Chromatic suggested that using exceptions avoided "unreliable string comaprisons, substring comparisons and regexes". Which it doesn't. It just moves them.

I have to parse that string with regular expressions to get the $cmd and $server values, every place it could be used

Why do they have to parse the string? (Ie. Why do they need to obtain the the server and command from the text?).

If you/they are going to 'fix' the error, then they will (should) be doing it at a point in the code where they already have that information at hand.

That is, if they are at a point where they could re-issue the command to a different server; or issue a different command to the same server; then they will be at a point where they have both available, because they provided that information to the call that cause the error (exception) in the first place.

If they are further back up the call hierarchy, all they can do is report the error (or ignore it), and they don't need to parse the error message, it already contains the relevant information.

not very DRY). And if I ever decide to change that error message I have to then track down all the places that regular expression lives (which is much, much harder than searching for a simple string in piles of code) and change them.

The DRY solution is don't put copies of the same regex in multiple places. Define the regex once, name it, and import it wherever it is needed.

Yes they might have problems if I ever decide to restructure my exception hierarchy (which is much rarer than changing an error message) but even that can be handled by having some special isa() magic to make the new classes still look like the old to old code. Try doing that when you're just using strings.

You're fixing the symptoms, not the problem.

If the error applies to the same condition, it is the same error. The error handler shouldn't need to change because you changed the description of the error. And that is just as easily achieved using a regex as it is exception objects.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.