chapter two

2 Narrative code

 

This chapter covers

  • Structuring code through storytelling
  • Discovering the five fundamental plots
  • Organizing methods by narrative level

We’ve explored the idea that code can and should be beautiful and divided that beauty into eight dimensions. Now, let’s focus on the first: storytelling. Every program tells a story, and the clearer that story is, the easier it becomes for others to understand, maintain, and extend. Let’s look at a quick Java example that we’ll revisit later in this chapter:

  validateMandatoryField(lastName, "Last name");
  validateBirthDate(birthDate);
  validateEmail(email);
  saveUser(firstName, lastName, email, birthDate, city);
 

The story is clear and easy to follow at a glance: validate and save a user. Stories organize complexity into coherent, memorable sequences. Like any good narrative, code should have clear characters, a well-defined plot, and a meaningful conclusion. I refer to this structured approach as narrative code.

The idea that code should be self-explanatory and read like its own story is not new. In this chapter, I present a structured way to make that principle explicit, building on well-known practices such as clear naming and small methods at consistent levels of abstraction, and reframing them through storytelling. This narrative lens is not meant to replace established design principles, nor will it resonate equally with every developer. It is simply a mental model that can help structure thought.

2.1 The plot

2.2 Code typography

2.3 High-level storytelling

2.3.1 Working with legacy code

2.3.2 Understanding the story

2.3.3 Simplifying the story

2.3.4 Levels of narrative: action, scene, chapters, and table of contents

2.3.5 Choosing where to break the story

2.4 The characters

2.5 The ending

2.6 Summary