Time is change

Today, I got a code review comment which was on a line of code I added when doing retry logic. (e.g. My process has failed, so let’s try it again.)
The line was something like this:


For those of you who don’t write code, a sleep simply tells the process to wait for the specified time (in this case, 1000 milliseconds — 1 second), and then continue executing after. I added this line of code so that it runs before each retry.

The code review comment was something like:
“Why are you sleeping? Why did you choose 1000? Please leave some comments.”

Great code review comment (no sarcasm).

I introduced this line of code as a response to another comment (from my mentor), who explained that “[I] wouldn’t see much change happen without waiting at least a second between retries.” To me, this meant that the state of the machine hasn’t really changed between any two retries, so let’s wait a second between each one so that the process that’s executed will have time to modify things. (i.e. variables are actually assigned their values, methods have completed running, etc. etc.)

Otherwise,the reasoning for this is simple. I simply wait a second between each retry.

But then that made me stop — isn’t my code running synchronously and not asynchronously? (Again, for you non-CS people, synchronously means lines of code are executed in-order — the next line will not run until the previous is finished. Asynchronously means a bunch of processes are not waiting for each other. They just run and they don’t care what the other processes are doing.)

So if my code is running synchronously, why should I call Sleep? It’ s not like I have to wait for something to finish running. All the previous lines of code are supposed to execute before the next line, so it’s not like one will not be finished before the other.

Feeling like I didn’t have sufficient justification to add that line of code, I asked my mentor — why put in the wait?

His response? Another question:

“What is time?”

I laughed at this, and laughed mostly at myself trying to answer the question. Well, it’s a measure, obviously. It’s a measure of how much time passes — but wait! I can’t use the word to define itself. It’s just a quintessential “base” unit. It measures…something. Clocks measure time. Time measures…itself. That’s what I told him.

Before I tell you his answer to “What is time?”, let me tell you his answer for “Why put in a retry?”

Apparently, there’s several reasons:

  1. Retrying without waiting is considered “rude”. Let’s say you issue an HTTP request. It doesn’t come back with OK, and there’s a failure. So you issue five more, right away. It probably won’t help you much. His analogy was similar to someone being flooded with emails and you want to get their attention. So you send them an email: “Hey. We need to talk.” They probably won’t see it. So you send 20 more. Now they have even more emails. Probably not going to help.
  2. If you’re doing something like an HTTP request, the server might take a while to respond. You want to leave a wait that’s at least enough time for the server to report a timeout. Otherwise, you’re just bombarding it.
  3. Coding standards and “typical” behavior.
    e.g Apparently HTTP requests are issued with 5–29 second waits, and there are 5 retries.
  4. It provides the user an opportunity to know that something is happening. Nothing will every take 0 seconds long. If you see a webpage’s loading circle spinning — it’s loading! That’s how you know it’s working. It takes time.
  5. This is what he calls his “philosophical reason” and also the reason why the reasons above even hold weight.
    “Time is a measure of change.” This was his answer to the question I was asked.
Time is a measure of change.

His reasoning is as follows. How different are you after 0 seconds? You’re not different at all. Nothing has changed. No time has passed. What about after 1 second? Maybe a little. Maybe you’ve twitched a bit. Maybe that oxygen that was outside your nose is now in your lungs.

Time is a measure of change and disorder. The more time that passes, the more we can expect things to be different.

So why wait before a retry? Because if you keep trying something when no time has passed, then nothing has changed. If nothing has changed, then you’ll only get the same result.

Calling Sleep(…) is just a matter of allowing some degree of change to happen. Maybe after five seconds, your PC has more memory to spare. Maybe it’s kicked some threads out and freed some resources. Maybe the server has less traffic. Who knows? So you wait a bit, hope something is different, and you try again.

But I thought about this a lot after our conversation. I thought about time equating to a measure of change. Those words stuck with me. We were, of course, talking in the context of coding and retry logic — but it’s very interesting and very compelling as to how this concept can also be relevant to one’s life.

I betray that logic sometimes. I’ve called people on the phone multiple times in quick succession, hoping that they’ll pick up. Of course, time passes, but not by much. What was I expecting? Was I expecting anything to change?

It also somewhat validates the concept of “taking a break” in a relationship. I always imagined it as a period to cool down, get some alone time, and then soak in some mental healing. I guess that’s true too. But a break is an opportunity for change. Leaving some time allows some people and/or the situation to change. (But of course, this doesn’t just happen naturally. When it comes to relationships, people need a little push.)

Otherwise, what exactly does this mean about me? I definitely am quick to frustration and impatience, or often get fed up tinkering away at something that is not producing results. Change takes time. It takes effort, too. If there’s no wind to chip away at the rocks, then you get no sand. But nothing is instantaneous.

It’s been years since I’ve had a personal blog. I don’t particularly like sharing my life with others, and when I think about old blogs I’ve had, they were usually very detached from recounting my life, or very juvenile. Time has passed since the last post I’ve written: have I changed much? I try to hope that’s the case. But that’s what people do, right? They fail and learn and retry. And hopefully something has changed in the in-betweens.

Until the next time. Right now it’s time to sleep.

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.