Is Execution time or Result time correct?

As David Schwartz says, status reporting operations such as getting disk free space, getting file size, checking if a file exists, etc., are fundamentally unreliable. A good way to think about them is that they return good faith estimates of their measurements, but there's the caveat that callers must not rely upon the values being correct as they could change at any time before, after, or during the measurement.

There's also the matter of requirements, both stated and unstated. Pretty much every function you write will have an unstated performance requirement that it not take 24 hours to execute. Certainly that's true for getting a date. What does it matter what you call the result of this function when the function is completely unusable? It's a purely academic distinction. In practical terms, the function is broken, and no result is ever correct.

To go further, I'm not even sure it's an academic distinction. You're asking if the "execution time" or the "result time" is correct. To be "correct" implies that the distinction will lead to either a right or wrong action and you need to know which it will be. What would those actions be?

If I'm right then I would do X, but if my friend is right I'd do Y.

What are actions X and Y? What would you do differently based on how this argument is resolved? For example, if this were a real issue in a ticketing system, would you end up closing the issue based on the outcome of your argument—neither of you fixing the 24-hour sleep? I hope not!


Consider this pseudo code:

fun getTomorrowsDate()
   sleep(getRandomValue())
   today = getCurrentDate() 
   sleep(getRandomValue())
   ret = today + 1
   sleep(getRandomValue())
   return ret

This is not very far from what is actually happening during EVERY function call. The operating system might interrupt at any time, so in a sense, those sleep calls actually do exist.

So unless you have taken very cautious steps of making your function atomic, the only difference between the above pseudo and your code example is that you have ensured an event that always have a non-zero probability to happen to have 100% probability.

David and John gave good answers, so I will not elaborate more. I just wanted to add this example.


A status-reporting function's result is correct if its result was valid at at least one time in-between when it was called and when it returns. This is the case for all status-reporting functions such as getting disk free space, getting file size, and so on.

At some point it has to get the status, and it can't do anything about the status changing before it gets it or after it gets it. So this has to be the rule or it would be impossible to write correct functions.

People often get this wrong. For example, they check for free space on a disk and then assume a subsequent write won't fail due to insufficient space. Or they call select and then assume a subsequent operation won't block. These are all mistakes.

Tags:

C