|
Boost : |
From: Brey, Edward D (EdwardDBrey_at_[hidden])
Date: 2002-03-20 16:10:11
> From: Stewart, Robert [mailto:stewart_at_[hidden]]
> >
> > It depends on why you're removing it, of course. Say you've
> > called program
> > A to create a script, which you feed into program B, which
> > you delete when
> > program B is done. If you get to the delete, and the script
> > file isn't
> > there, you know you're in trouble. You wonder why program B didn't
> > complain. Maybe A didn't put the file where you expected and B used
> > internal defaults. Better to get a nice exception rather
> > than have the
> > sequence silently "work".
>
> I don't buy it. If this is important, program A will check
> to see that the
> script exists before calling B. If B doesn't complain about
> the script's
> absence, then it isn't important to B. When A regains
> control, it's only
> concern is to ensure that the script no longer exists; no
> exception needed.
That approach works, too; however, it is more coding (plus requires control
over the design of B). Since we need to delete the file anyway, it is
convenient to bundle the existence check into the delete call. That way the
algorithm is simply Call A, Call B, Delete File. No intermediate checks are
needed, but there is still good diagnostics. True, one can live without
this, just like one can live with a remove that always throws on any error
and lot of try/catch blocks.
> > Checking that a file that you expected to exist actually
> > exists is likewise
> > useful for spotting bugs that may otherwise be hard to detect.
>
> Please give me good examples of this. I can't think of one.
Such was the motivation for my above example. If you want to get more
concrete, here's another one off the top of my head:
Presume that you are making a utility to wipe files. You overwrite the file
many times and then delete it. If for whatever reason the delete fails, the
user definitely should be notified of it.
I'd take this a step further, and say that any time the user asks to specify
delete a file, he should be notified if the delete fails. That gives him a
heads up that his view of the file system is out of date and/or there is
some other entity (possibly previously unknown to him) working with the same
files as he.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk