There are few reliable absolutes in this world. One I have relied on is the idea that checking if a file exists before doing something with it just creates an unwanted race condition. Meaning between the check and the attempt at usage, the OS was free to do whatever it liked with the file. So I had no right to expect anything to stay the same and that there was no good reason to ever do this.
However, after offering this advice recently I was presented with a counter argument that such a check can preserve limited file lock resources. The race condition diffused, not by pretending we know what we don't, but by claiming to know what is more likely.
At first this just sounded to me like someone trying to rationalize some bad code but I can't say I'm as certain as I once was.
If a use case that makes sense of such code really exists I'd love to hear it. If it does I'll need a compelling argument for its need because such code is going to be very difficult to test completely.
To boil it down, I've made a habit of telling people to stop checking if a file exists before opening it. Are there exceptions to this rule profound enough to consider it bad advice?