If you’re reading my blog and you haven’t seen Futurama, watch an episode. For anyone who hasn’t seen it, here’s a brief synopsis: Our hero, Phillip J. Fry, pizza delivery guy, is delivering a pizza on New Year’s Eve 1999 when he inadvertently gets frozen for 1,000 years. He awakens in the year 3,000 and ends up working for his great-great-great-…-nephew, Prof. Farnsworth, who is over 100 years old and never looked better. Fry’s new job is delivering packages for Planet Express, a package delivery company Prof. Farnsworth put together with his faster-than-light spacecraft.
In one particularly suspenseful episode, Prof. Farnsworth’s clone is trying to figure out how to repair the Planet Express ship. It uses an exotic engine powered by exotic materials (dark matter). At the critical moment, the clone exclaims, “I understand how the engines work now. It came to me in a dream. The engines don’t move the ship at all. The ship stays where it is, and the engines move the universe around it.” This is like laying a sheet of paper on a flat surface, just touching it with your finger, and moving it around with your hand. Your finger’s location stays the same relative surface, but the paper changes its position relative to the ship. It’s a completely ingenious design, but what if Prof. Farnsworth built another ship? Now imagine adding a second finger to that piece of paper and another hand to move the paper relative to that finger. What if the two ships wanted to go in different directions? The ingenious design is now completely wrong and cannot be fixed. In order to add another ship, the entire design has to be thrown out.
There is a similar situation in computer programming. It used to be called a global variable. Now it’s more trendy to call them static or class variables. These are variables that hold a single value for the entire system in which the class (or global variable) operates. At first glance, they can seem to be an ingenious way to solve a problem. Any time you think about using them, though, you should think about what might happen if you add another “ship” to the system. Who knows? Maybe the whole universe would implode.