in reply to Re: if (ref $value eq "ARRAY") {
in thread if (ref $value eq "ARRAY") {

Even if you could recover gracefully from wrong input, it's probably a bad idea. If you get wrong input, then somewhere along the line someone screwed up, and about the worst thing you can do is hide the problem (or at least pass it on to another chunk of code further away from the original) and make it harder to debug. That sort of false "defensive programming" isn't just a waste of time, it's actively harmful.

In general, I like to write code that fails -- gracefully, mind you, not locking up the machine or any such -- as soon as possible on bad assumptions. Makes it easier to find bugs.

--
F o x t r o t U n i f o r m
Found a typo in this node? /msg me
The hell with paco, vote for Erudil!

Replies are listed 'Best First'.
Re^3: if (ref $value eq "ARRAY") {
by Aristotle (Chancellor) on Aug 24, 2002 at 04:07 UTC
    That's what I was getting at. It's not actually possible to really recover from such errors in a sensible way, so I want to croak at some point anyway. Since Can't use string ("...") as an ARRAY ref is just as good as a custom croak message, I simplify my life by skipping checks for conditions that wil cause the code to blow up anyway. Instead I check for semantic problems where I need to hit the selfdestruct button myself because Perl won't know to do it for me.

    Makeshifts last the longest.