--- Comment #7 from Dimitri Sabadie <dimitri.saba...@gmail.com> 2012-10-29
14:38:19 PDT ---
(In reply to comment #6)
> Of course, you test whether the file exists before calling isFile, isDir,
> isSymlink. That avoids getting the exception when the file doesn't exist. But
> those functions can still be called without having first checked whether the
> file existed, and it's perfectly possible for the file to be deleted between
> the time that you check that it exists and you call isFile/isDir/isSymlink.
> those functions must handle the case where they're given a file which doesn't
> exist or is otherwise inaccesible (permissions could also make them fail and
> could make exists fail in the same way). As such, those functions have only 3
> options when they are unable to determine whether the file is a
> 1. Throw an exception.
> 2. Return true.
> 3. Return false.
> #2 is patently wrong, because if the file doesn't exist, claiming that it's a
> file/dir/symlink would be total lie. And #3 doesn't really make sense either,
> because that would mean that the program would be being told that the file
> wasn't a file/dir/symlink when it doesn't actually know what it is. After a
> call to isDir returned false, it could end up assuming that file operations
> would work on it (since almost everything is either a file or a directory) and
> then do who-knows-what based on incorrect information. If
> isFile/isDir/isSymlink can't determine what the file is, then it really
> make sense to return either true or false. So, the correct way to handle it is
> an exception. Not to mention, that allows for much better error-handling. If
> exception is thrown, then the program may be able to respond according to what
> the error code in the exception was (e.g. it may be able to indicate to the
> user that they don't have permissions to read the file).
> I think that it's quite clear that throwing an exception is the correct thing
> for isFile/Dir/Symlink to do when they are unable to query the file for
> it's a file/dir/symlink.
I well listen to what you said, and I still don’t agree. The problem is in your
own solution :
> […] That avoids getting the exception when the file doesn't exist. But
What the point of avoiding a function to throw? You said there’s function to
check if the file exists (may you tell me which please?), so we can call it
before to call isFile without throwing exception -> it’s a huge design problem,
because we will never really catch the exception. And it’s quite logic, because
isFile, isDir or isSymLink, by the responsibility they have, shouldn’t check if
the file exists. In worst situation, the fact the file exists may appear as a
precondition of the property, but an exception…
I’m afraid to figure out how, nowadays, people want to overuse features where
simple and more adapted ones would be far away enough… You mark this thread as
WONTFIX, it’s a pity, because there’s definitely a problem around those
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------