Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: A new idiom -or- I Hate Unless

by cLive ;-) (Prior)
on Aug 22, 2004 at 21:34 UTC ( [id://384975]=note: print w/replies, xml ) Need Help??


in reply to A new idiom -or- I Hate Unless

Because of the design of the code (not to mention my deadlines) refactoring the error code out into a seperate function really isn't possible

Maybe I'm missing something here but, if you're already rewriting these error handling cases to make them more readable, how much more work would it be really to add a sub/module to handle the errors?

You can have the added benefit of working on how to deal with errors more comprehensively over time. For example, here's a snippet of our "fatal error" method under mod_perl (not everything, just the interesting bit, and rewritten to run standalone rather then using some internal methods we use).

sub fatal_error { my $err = $_[0]; my @caller = (); my $i=-1; while ( caller(++$i) ) { (caller($i))[1] =~ /5\.8\.0/ and last; # don't log apache mod +in trace push @caller, sprintf("-> %s at line %s\n", (caller($i))[1,2]) +; } open(LOG,">>/path/to/err_log") or die $!; print LOG `date`,"$err\n",@caller,"\n"; close(LOG); # display fatal error page, since this is in a web environment }

Like I said, this is just a snippet, leaving out the emailing of the error to me, the logging in the local DB, and the centralised logging for later analysis.

If you start refactoring as you go, you'll have much better control over how errors are dealt with and, when you get an idea on improvement, you can easily add it in.

Yes, deadlines are there, but by not factoring refactoring (intended :) into your time lines, you're creating more work down the line.

If convincing the powers that be of the wisdom of this is problematic, buy your boss a copy of Peopleware, make them read it, then schedule a time where you can discuss the issues it brings up, and how you can implement them to make your work more productive.

Saving time now by ignoring problems is a false economy.

.02

cLive ;-)

ps - oh, and I'd call it like this:

unlink $file or fatal_error("Couldn't delete $file: $!);

Replies are listed 'Best First'.
Re^2: A new idiom -or- I Hate Unless
by erikharrison (Deacon) on Aug 22, 2004 at 22:08 UTC

    You're completely right of course. The issue with not refactoring is that every error condition is slightly (or, in a few cases, vastly) different. The deadlines are on the order of hours, not days or weeks, and it'll take some thought on how to reorganize the code so that these slight variations can be handled from a few functions. It's not so much fail-and-log or fail-and-die. This is "fail and connect to different db to pull out sensible defaults for unset fields in existing database but only if called in a certain context".

    In other words a nightmare. But your point stands that if I can refactor now, the extra ten minutes is probably worth it.

    Cheers,
    Erik

    Light a man a fire, he's warm for a day. Catch a man on fire, and he's warm for the rest of his life. - Terry Pratchet

    janitored by ybiC: Replaced "run-on phrase using dashes" with balanced quotes and italics, for to avoid lateral scrolling

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://384975]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2024-04-20 06:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found