design - When your method fails, but succeeds... Would you return a failure or a success? -


I suspect that there is a definite answer but I have a lot of interest in this opinion on different topics. So a communication wiki so

You are designing a method. It is a purpose, so you are designing it in the first place. A collar uses your method and the method fails, but, take and see, the ultimate goal of being the cause of the existence of this method has still been achieved - thanks to external circumstances that are out of your control or Any kind of magic, do you choose, will you report this situation as collision failure or success?

Let's choose a trivial example. You are writing a DeleteFile function. It takes a file path and removes the file. Someone calls this path, provides a path. The function file looks, but it does not exist. This is not a permissible issue or nothing, the file is actually missing, that any other process removed it a microscand first, and perhaps it was never in existence. This task has failed to do its job, so it should report failure ... but the only reason why the user calls this function, to ensure that no file exists, and, Vola It's not so, so it's a success.

I look forward to answering, like, "in your values ​​there are more verbatim", and I am happy to return an important result as a clear result, but you (and why) back The primary success flag of celebration, success or failure? Will it be wrong with the flag beyond the BUT_DOES_NOT_EXIST_ANYWAY, or will it be true with the flag BUT_THANK_SOMEONE_ELSE?

Edit

Please do not answer those that apply only for the above example I am asking about the general situation, in which the method There is no criterion for it or it is not possible to call it incorrectly for any other reason.

When learning to write new programmer functions, pre-condition and < Strong> postcindition are often present. Preconditions should be met for assumptions that work your way properly. Postcondition guarantees that your method explains the state of the system after the execution.

I think a proper precondition for expecting to call the deleteFile method is that the file is currently present if the pre-condition is not met, then the method Should be failed , even if there is a casual, postconditioning in the crossroads.

Now, if your method is called , DeleteFileIfExists , it is a different story that you did not put such a strict pre-condition on this method.


Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -