Ivan Kusalic - home page

I'm Stupid When I'm Tired

As the title says, I’m stupid when I’m tired. Seriously, this is not a joke! Fatigue affects my performance across the board. Intellectual capabilities needed for being a software engineer are affected more than most.

I’m going to ramble a bit here, recollecting a particularly embarrassing episode I had yesterday. If you are often on the verge of being sleep-deprived or just plainly tired, by the end of this post I hope you’ll reflect on that behaviour a bit.

Consequences observed

Half a year ago I used to sleep about 5-6 hours during the weekday. As the week progressed I’d become more and more tired, and then I’d catch up on the sleep over the weekend. This was the norm for me. I did not think anything about it. Sure, I was a bit low on the energy, but I guessed that’s just who I am.

I decided to break this habit and this has drastically increased the quality of my life. Nowadays I try to avoid having two consecutive nights without 7 or better 8 hours of sleep.

I observed many consequences of not having enough sleep. In general I had low energy levels. I was more likely to make stupid mistakes. I was often more affected by alcohol, and this was less predictable1. I was more likely to succumb to small temptations, e.g. overeating. I was also more likely to do things I consider to be negative, such as interrupting people while they are speaking. I would get more confident than the situation warranted.

But it went beyond small things. I was rarely spontaneous – I was willing to do things outside of my routine only if they were planned and I was already committed. I did not face the bad tendencies in my relationship and let things accumulate. In general I was just enjoying the life a bit less than I could have.

Sometimes I would just feel less intelligent. My mental capabilities were even severely impacted. I thought I could normally detect those states. As you’ll later see, it turns out that’s not always the case.

Effect on software engineering related tasks

When it comes to fatigue and software engineering related tasks, I would just go to autopilot. That ment that I would change the way I think and even how much I actually think. I would do more trivial pattern matching, and less serious in-depth thinking. If I encountered a bug, I was inclined to try random variations2 instead of thinking it through. I would basically become a fortune cookie programmer3.


A bit of context before describing the effects of being fatigued I experienced yesterday.

This week

Lately I’m careful to sleep enough. But somehow I did not sleep that much this week. On Monday I was at a software craftsmanship meetup. After it finished we went to have a few drinks and so I came home after 3 AM. I hed some four hours of sleep before going to work. On Tuesday I had a dinner at friend’s place and I came home around 1 AM. I wanted to quickly check email, but somehow this spiralled out and so I managed to get only five hours of sleep that night.

Now, that would normally cause me to be a bit tired on Wednesday, but I would still be mostly normal.

Incidentally I decided to cut down on my caffe intake this week. On a typical workday I’d drink four or five cups a day. But I decided to only have one cup in the morning and one after lunch. I did not think that this has a big impact, as I do not really feel differently no matter how much coffe I drink. Now I’m suspecting it has a bigger effect on me than I thought.


I was feeling a bit tired during the day, but I did not think much of it. Tomorrow is going to be a public holiday anyway, so I’m definitely going to recharge my batteries.

And so the day was progressing. I was feeling increasingly tired, but I still thought it’s not that bad. Well, it was, worse than I expected.

I was running some load tests that day. Just before going home colleague and I wanted to take a better look into the load-testing code.

The load-testing tool was written in Scala, a language I only recently started using and the aforementioned colleague did not have any experience in. But I was feeling confident. I was learning it at the rate that made me happy, almost proud. And I’ve already written quite a bit of Scala code. The code I was working on was also fairly complicated, AWS management tool implemented in Akka and Spray, written in purely functional style using a lot of advanced language constructs.

And so we looked at the code. We knew it is reading and parsing the logs and later replaying them at the desired speed.

But the problem was that for the life of me I could not figure out how was the iteration over the logs happening. What the hell was iterating in that code?!

We’ve stumbled upon the run method – well, that must be doing something interesting. I quickly skimmed through the code and discovered the snippet that must be doing the iteration.

iteration snippet

var i: Int = 0
try {
  for (
    line <- config.limit.fold(lines)(lines.take);
    entry <- parseEntry(line)
  ) {
    i += 1
    if ((i % 25) == 0) print(".")

    if (active) {
      scheduler.waitUntilScheduled(entry, this)
      if (active) replayLogEntry(entry)
      else Breaks.break()
    } else {
} catch { case e: Throwable => write("Exception on main thread: " + e) }


My thought process at the time

Ok, so there is this for thingy, but that is just unpacking some futures or doing some other monadic operation. I won’t foll for the trap. I know this is not iterating! Ok, so there is this fold, I’m currently having a bit of trouble to parse what it’s doing. But great, it’s invoked on some Option object, so no worries, safe to skip it, it most likely just returns all the lines. Wait, the name to which the <- thingy is pointing is in singular. Well, that’s a bit weird, but most likely just a minor mistake on the implementer’s side. Wait, there is a function being invoked in the next line. Well, better check that one.

This spiralled out a bit. I still couldn’t find anything that iterates, and so we went back to the snippet.

This just makes no sense at all! There is some var i being updated, see there is i += 1, but how is it being updated?! I just do not get this!

The colleague who was surprisingly patient pointed out that there is a for keyword there, but I dismissed him saying I’ve used the for in the past in Scala and it’s just syntactic sugar for maps and flatMaps and nothing else, so no iteration. Even the word “map” was not ringing the bell.

Finally I decided to just asked the more experienced colleague with whom I paired a lot on Scala code. He looked at the code, saw that the lines are coming from a stream and said that the for is doing the iteration.


At that point I’ve noticed that the for uses ( & ) instead of, in my experience more common { & }. I asked would it behave differently if the type of parentheses was different.

Of course not. He went on to explain that in this case the for is not used with yield like in our AWS project, and that it is doing plain iteration. The bell finally rung!

By this time both of them were looking at me with strange eyes.

The experienced Scala colleague paired with me enough times and reviewed enough of my code to know that I’ve converted maps / flatMaps to fors and vice-versa many times. What’s more important, whenever we paired or I had questions, I wanted to understand all the constructs at the fundamental level, and so he often explained me things in-depth with proper CS constructs I was familiar with. He also complimented me often saying that I’m learning Scala surprising fast. And I actually try to understand all the constructs I’m using and normally succeed at this.

What the other colleague thought I’m not sure, but there must have been a flicker of a disappointment in his eyes.


When I was on the way home, I felt ashamed. I also barely made it, as I almost had the eye poked out with an umbrella. By then I understand just how exhausted I was.

When I turned on the comp at home, as usual I tried to mount two true-crypt partitions. I remember thinking at one point Ok, so next I need to select the directory in which to mount this containter and then only 2-3 seconds later I pressed OK without selecting the mount directory.

Edit: As luck would have it, while validating the link for the truecrpyt website I found out that it’s not deemed secure anymore and even the official website says the same. All of this as of today! Oh well…

The only good decision I made was to skip drinking with a friend with whom I had plans.

In the reflection, what was really strange about this episode is that I did not notice right away how tired I was. How I could get to that level of idiocy without detecting it still escapes me.


I really am stupid when I’m tired. A few months ago I started getting more sleep and it only positively influenced the quality of my life. I have much more energy. And the importance of energy levels should not be underestimated. I’m also more spontaneous.

I even started taking it to the extent that I refuse to watch new episode of a show I particularly like if I’m tired. That would be wasteful as I would not enjoy it as much as I could4.

I enjoy the life more. And I highly recommend you to change your behaviour if you currently do not care about being tired.

I guess I should also eliminate coffe rituals from my rutine, as I’d like for my energy levels to be more consistent and less susceptible.

I’ve decided long time ago that long working hours do not work for me. This is just an additional confirmation. But this is controversial topic, so I’m not going to spend more time on this.

I also think that it’s a irresponsible behaviour for a professional to let the fatigue influence his capabilities regularly. I’d like to think that something like yesterday will never happen again, but that would be wishful thinking. I will however try to minimise the chances of this happening again.

Finally I know how it feels to be stupid. I also know how much I hate it. This is actually a good thing, as it will prevent me from visiting this state of fatigue too often.

Well, I’m tired right now, and although I’ve taken the day-off tomorrow, I’m going to sleep soon. Good night and sleep well.

  1. Not doing anything negative – I do not believe in alcohol ever being an excuse. It was just that the amount I could drink would, in extreme cases, vary by the factor of 5.

  2. Like trying if +/– 1 in the loop works without thinking why. I detest that approach unless it’s used with a really compelling reason.

  3. I’m not sure if I’m the first one to use the term “fortune cookie programmer”, but I really like it. You can probably guess the kind of developer it describes…

  4. Yep, I’m also the type who saves the best part of meal for the last bite.