rockym93 dot net

archive · tags · feed

The Stack.

27 January 201402:58PMcode

So there's this concept in computer programming called a stack. A stack is a particular way of arranging bits of data in a sort of list. The interesting thing about stacks, though, is that not only do they do stuff in order, but you can only work at one end of that order. It's a type of structure called LIFO, which stands for Last In, First Out. Which means basically what it says: the most recent item on the stack is the only one you can write to ("push") or read off ("pop"), so whatever you put in last is the first thing you get back out.

Stacks are useful for a lot of things. One of the slightly unintuitive ones is reversing the order of a list, without having to (directly, at least) implement a bunch of counting and ordering code. If you've ever taken a bunch of things from one pile, and put them one by one on another only to find that the thing from the top is now,on the bottom, you'll understand the basic principle.

The point that I'm trying to make here is that sometimes computer scientists spend a lot of time and effort trying to recreate in code something that's utterly second nature in the physical world.

The reason I bring this up, is that over the last nine-ish months, I've been stacking books in my bedroom. Occasionally I put one on the stack and then read it straight away (see: Matter) but most of the time they got buried because I was a little busy.


The practical upshot of this is that I have a perfectly reverse time-ordered pile of books.

This is not actually ideal. Mostly because it means that the bottom book, Fragile Things by Neil Gaiman, may never actually get read. Which is bad, because not only is it surely a very good book, but it's also a book I was lent by somebody else, who would probably like it back one day.

So, we need to pop these books off the stack, one by one, and push them onto a new stack. The upside is that these books are now in ordinary chronological order, and so will be read from the oldest first.

Uh, push push?

The downside, which depending on how you look at it, may also be an upside, is that it's slightly more difficult to add new stuff to the pile. Which, oddly, is a difficulty which is possibly translated into the programming version of stacks too, albeit not intentionally. I mean, I think (at a pretty low level at least) it's easier to add stuff to the end of a sequence than the start, but I don't actually know enough about memory allocation and stuff to say for sure.

The actual point of this exercise was this: here is my reading list for 2014. It's not quite the fifty book challenge, but if I can have an empty stack (although strictly speaking it's now a queue) by the end of the year, well, I'll be pretty pleased with myself.

read the comments

< 2014 Take a deep breath. >