I am always really excited when some abstract data type seems directly applicable to real life. It’s like a little nod from God saying, “yes, computer science and logic and math are real things! Happy learning!” Today we’re going to talk about stacks and queues.
These words both have special meanings in computer programming: A stack and a queue are both ordered collections; that is, they keep track of things, and let you handle these things in a specific order. A stack is “last in first out” or LIFO, and a queue is “first in first out” or FIFO. Think about a stack of plates: The last one you put down is the first one you’ll pick up. Think of a queue (people standing in line) at a store: the person who’s been in line longest gets helped first.
Let’s focus on one thing: the plates on the bottom of the stack. Let’s say you own 10 plates, and, on average, you run the dishwasher with 5 dirty plates in it. If you keep all the plates in one stack, that means the bottom five plates will never be used.
I think the human attention span is a stack, but to get work done, we need a queue. Last week, I had a really unproductive day. I would start working, then I would get an email, then I would get some notification about a meeting, then I would get some question over Skype, then I would get an email. As each of these things came in, I would work on it immediately. Last in, first out. My attention span was a stack. What was I working on when I got that first email? Who knows! It got pushed to the bottom of the stack, and because I was running a stack, not a queue, it kept getting buried. My important work was like the bottom five plates in the cupboard. What a terrible afternoon!
Another way of thinking of this problem is that is has a lot of work in progress. I would start a task, then interrupt it, start another task, then interrupt it, start another task, and the stack would keep getting deeper! We learned from The Phoenix Project that work in progress kills productivity. All those things on the stack took five, ten, maybe thirty minutes of my time, and none of them were done. It’s like I went bankrupt by making a bunch of $10 loans and then never collecting anything.
In many ways, the queue is the opposite of a stack. In a queue, the oldest thing is the one that gets worked on first. This has a very important property: queues will empty. If you can handle tasks even slightly faster than they arise, you will eventually do all the tasks. And, there will only be one task in progress at a time: the task that has been in the queue the longest.
I really think that the different between stacks and queues is a key to understanding what a to do list or a schedule is really for: Human attention, and the activity you receive, is inherently a stack, with newer things crowding out older things, but productive work is inherently a queue, with older things getting finished before they’re too old. A schedule is a buffer that lets you transform a stack into a queue.
Let’s go back to my terrible afternoon. What if I had just maintained a list of things to do when I was done coding? I get an email, a question over Skype, a survey about lunches, whatever, it goes on the queue. Then I keep coding. When the code I am working on is done, the queue advances, and I get the oldest email. Then I get the second oldest email, etc. The queue will empty, which means I will get things done.
So, there are approximately six million apps and websites for tracking to do lists, and it doesn’t matter which you use. (Heck, when I was in college I just carried around a sheet of printer paper with everything I need to do on it. I use Trello now.) But really, the basic function of a to do list is to be a big enough buffer that you can turn the growing stack of input from daily life into a queue that you can empty.
Till next week, happy learning!