in reply to Re: Re (tilly) 3: Seeking Feed back
in thread Seeking Feedback on Chat Program (was Seeking Feed back)
I am commenting that your initial version failed to log critical information that would make it possible to debug the problem later. And no matter how controlled the environment may be, you are not going to convince me that you won't ever have bugs to track down.
I am glad that your current example does that better. It does not do it well enough to make me happy, but it is better.
Here is a better version of the same thing that you have:
Why better? Well suppose that some bright sysadmin gets the idea of having your data mounted from another machine over NFS. (This is not an unreasonable thing for a sysadmin to have reason to do.) With the revised version you will get notified that flock no longer works. With the original version the error would be silent until someone noticed sporadic loss of data over 6 months and thought to wonder why. (At which point you read your code and have no a clue where it could fail.)sub ret_read_fh { my $filename = shift; my $fh = do {local *FH}; unless(open($fh, "< $filename")) { log_error("open '$filename': $!"); return; } unless(flock($fh, 1)) { log_error("flock '$filename': $!"); return; } return $fh; } sub display_values_from_file { my $fh = ret_read_fh(shift); if ($fh) { while(<$fh>) { print process_line_from_file($_); } } else { print "Error opening file. Please try again later!"; } }
My points?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re (tilly) 5: Seeking Feed back
by orkysoft (Friar) on Jul 06, 2001 at 01:52 UTC |