Telling a Story with Your Code
Telling a Story with Your Code
A story is an accounting of a set of events or people, real or imaginary. Code is either a system of words, letters or figures substituted for other words, letters or figures, especially for the purposes of secrecy or programming instructions. Sometimes, while reading code (computer science), both definitions apply. In the talk about inclusivity, everyone, all humans, should be able to use the applications or products we build. If we are building for everyone, why then are we writing code like we only want those with our decoder ring to be collaborators? Or we only want the computer to be able to decode what we wrote?Whether we are writing a novel, a short story, an article or code, our audience is always our fellow humans. The computer can interpret the statements whether we use the most concise way of writing an algorithm or whether we use the most readable way. Sometimes we will care about the optimization of a line. We will need the line to be faster. What we always care about is whether or not we can understand what the line is doing when we read it. Having to guess about what a line of code is doing fuels the imposter syndrome that so many of us fight with.For the most part, we build our applications with high-level programming languages. Programming languages that are meant for humans to be able to understand and must be compiled or interpreted for computers to understand. If we are writing in a language that will be translated for the computer, why are we still writing code that requires so much translation for humans as well? What is telling a story with your code?Some people think programming is science and math with rules and formulas. Others think programming is an art. The computer will see code in black and white, right or wrong, on or off — two choices. Humans will read code and will read it subjectively, the same way they read a news article or Shakespeare. Art is subjective, and because we are critics, we tend to stereotype art as without rules whereas, with science, we want to be methodical, follow a formula, prove something "right." Even then, science and art are not all that far apart. Architecture both uses math and science, and yet, we call buildings beautiful. We try to find new ways to combine the rules into more beautiful structures. Art uses science when combining two colors to make a new color and has rules for composition. Programming is also both science and art, and writing code is still a form of writing. Where do I start telling the story?The story starts with the architecture and the folder structure. Uncle Bob says that "good architectures scream their intended usage." A portion of the architecture is the folder structure and naming the folder structure. On naming things, Uncle Bob states that "choosing names in programming is as important as naming your children."On that, a programmer needs to know the business and have good communication with the stakeholders. The group needs to decide on a taxonomy. If the naming of things is based on the terminology in the business, then the programmer can talk to the stakeholders and discuss the code with more clarity. Remember, changing the names of things in code is usually a cheap operation. A good coding editor does most of the work for you. Knowing everything about the business on day one is not necessary.In naming the nouns and verbs of programming, we start with the taxonomy of the domain or business. We may use a thesaurus to find a better word for a word that doesn't seem specific enough. We may question the same word being used in different ways. This leads to a comparison of DRY principles in writing a novel and in writing code.In writing a novel, I use a thesaurus to vary my word choice and see if I can find a more descriptive word when I realize I used the word "walking" 20 times and maybe "strolling," or "running" was a better choice. In programming, DRY means I don't want to write the same block of code multiple times — I don't want to have to maintain code that does the same thing more than once. In programming, I absolutely want to use the same word to describe the same thing every single time. I want consistency with word choice. What is an example of telling a story with code?Look at the following two code samples:
Graphic courtesy of author.
Reading
Writing
Reviewing/Refactoring
About Latisha McNeel
Latisha McNeel is a Full Stack Developer at G2i.