I doubt that there is a definite answer, but I am interested in different opinions on this issue. Thus, the Communite wiki.
You are developing a method. This serves the purpose, so you design it first. The caller uses your method, and the method fails, but, and now, the final goal, which tempts the existence of the method, nevertheless is achieved - thanks to external circumstances that you are not under your control or some kind of magic, you choose. Could you report this situation to the caller as failure or success?
We choose a trivial example. You are writing the DeleteFile function. It takes a file path and deletes the file. Someone calls this function by providing a path. The function looks up the file, but it does not exist. This is not a permissions problem or anything else, the file is really missing. Perhaps another process deleted it a microsecond ago, and perhaps it did not exist at all. The function did not complete its task, so it should report an error ... but the only reason the user should call this function is to make sure that the file does not exist, and voila, it is not, therefore it is a success .
I expect such answers to be “just more verbose in your return values”, and I’m happy to return a detailed result in the form of free information, but what (and why) would you return, success or failure as the main flag of success? Will it be FALSE with the additional flag BUT_DOES_NOT_EXIST_ANYWAY, or will it be TRUE with the flag BUT_THANK_SOMEONE_ELSE?
EDIT
Please do not give answers that apply only to the example above. I ask about the situation as a whole, including when the method has no parameters, or for the wrong reason, it cannot be called for another reason.
GSerg source share