Purpose Statements


In The Hitchhiker’s Guide to the Galaxy, programmers spend 7.5 million years waiting for their computer to compute the answer to the universe. They then realize that they don’t know what the question is. This is a perfect example of the importance of writing purpose statements when programming. You absolutely cannot start writing a function without thinking very carefully about what it does. What does this piece of code compute? Why am I even writing it? If you cannot answer this question, it is probably useless to write that program let alone run it. Had the people programming the computer in the book followed this crucial step of the design recipe before running their program for 7.5 million years, they would have realized that they needed to formulate the question before the answer. The result of a computation is utterly meaningless without an interpretation. A common misconception is to think of the sole intention of purpose statements as documentation for future code maintainers (could be yourself). Rather, purpose statements are an exercise by which the programmer proves to themselves that the code they are writing is both necessary and coherent in function. Making bad design decisions is a very natural part of the development process, however, this step serves as a sanity check before you start chasing a rabbit to wonderland without even knowing what the rabbit looks like.