Recap

Part 1 discussed how a stack works like a deck of cards where you can only add and remove cards from the top of the stack.

Hypothetical Use Case:  I want to buy a house.

Picture an real estate office, empty except for a tiny desk as wide and deep as a single sheet of paper.

Does this house make sense?

You first put down an information sheet on a house you’re interested in buying.  Then you get a clean sheet of paper and write “Is buying this home a good idea right now?  Please use a new sheet for your answer and place it on top of this stack.  I’ve placed the house information sheet under this one.  Call me when you’re done”.  You then leave the office and ask your associate who is a real estate agent to enter the office and get to work.

Delegation

The real estate agent takes a peek at the house info sheet and your question on top, then takes out a new sheet and writes down a series of statistical questions needed to make a reasonable guess.   On another clean sheet the agent writes “Please research the questions on the sheet below this one and summarize on a new sheet added to the top of the stack.  Call me when you’re done”.  The agent leaves and calls in the statistician.  

Dirty Work

The statistician dutifully answers the agent’s statistical questions using several new pieces of paper, and summarizes on a new sheet.  Since no one needs the sheets used for all the intermediate work, the statistician discards them and only adds the summary to the top of the stack.  The statistician calls the agent back in.

Taking Credit

The agent uses the top sheet to generate a report on a new sheet.  Before adding the report to the top of the stack, the agent discards the statistician’s summary, as well as the sheet with all the original statistical questions.  The agent doesn’t like to share industry secrets.  Instead the agent places the report on what is now your original question sheet and calls you back in.

Cleaning House

You now have your answer on the top of the stack as you requested.  You throw the rest of the papers away and decide to stay in your condo.

Conclusion

This may seem contrived, but consider a situation where you had not three people, but a task that required 100 people each contributing a small amount of specialized work.  Conceivably, they could all operate using the same stack of paper on a single desk, and as long as none of the people accidentally mixed up the pages below what they were asked to look at (thereby corrupting the stack), everything would work out nicely.

In low level programming, the stack of paper represents a block of memory.  The stack used in Blimp Code represents this common limitation.  I’ll discuss how that works in Part III.