Re: opening a file
- From: Tim Greer <tim@xxxxxxxxxxxxx>
- Date: Wed, 14 Jan 2009 09:07:06 -0800
cartercc wrote:
On Jan 14, 9:30 am, Chris Mattern <sys...@xxxxxxxxxxxxxx> wrote:
If you don't care whether the file opens, why are you opening it?
My point was that you can conjure up an exception for every rule.
In my job, I constantly write and run scripts that open and close
files. Many of these scripts are on-the-fly scripts. I've been at work
for three hours today, and already I've written two of these kinds of
scripts and have run around two dozen. Very rarely do I bother
checking the return value of open(), and I don't ever recall having an
open fail. The biggest problem I have is with typographical errors,
and warnings catch those.
I totally agree with error checking, and the scripts that I write for
others to run ALWAYS include this kind of error checking. The scripts
that I write FOR MYSELF for processing files rarely do, however,
because open() never fails and I'm too lazy to take the extra effort
(small though it may be) to type out the 'or die' clause. My quibble
is not with the rule, but with the idea that the rule has no
exceptions. Every rule has exceptions.
If it's any consolation, I am the only one that suffers the penalty
for not checking whether or not a file opens in my own scripts, and I
am perfectly willing to risk incurring the penalty to keep from typing
a few extra keystrokes with every invocation of open. This is a
deliberate choice on my part, and I have never sought to impose that
choice on anyone else.
CC
I suppose you're aware then, that if it did fail on a file that you did
need data from, that you would spend more than the 1 second a warn, die
or method you create to note the problem, and start digging through the
file, adding the checks, only when it does fail. If you didn't make a
typo and the file exists and is readable, then yeah, you'll probably
never have a problem. But, the same is true of checking the return.
You still would never have a problem and never see it die, warn or log
an error -- even if it silently ignores it (due to the return value)
and moves on fine, in a friendly manner. I couldn't imagine how it's
really saving any time at all by not adding a simple check. If
anything, create some very simple module or library and use that for
the open routines on all of your scripts, even if to just log and
happily and blindly move on (because yeah, sometimes it's okay to just
keep moving). Anyway, it's certainly up to you if it's just your code
and you affected.
--
Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc.
Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers
and Custom Hosting. 24/7 support, 30 day guarantee, secure servers.
Industry's most experienced staff! -- Web Hosting With Muscle!
.
- References:
- opening a file
- From: George
- Re: opening a file
- From: cartercc
- Re: opening a file
- From: Jürgen Exner
- Re: opening a file
- From: George
- Re: opening a file
- From: Tad J McClellan
- Re: opening a file
- From: cartercc
- Re: opening a file
- From: Chris Mattern
- Re: opening a file
- From: cartercc
- opening a file
- Prev by Date: Re: opening a file
- Next by Date: Re: opening a file
- Previous by thread: Re: opening a file
- Next by thread: Re: opening a file
- Index(es):
Relevant Pages
|