8 How to get better at naming things

 

This chapter covers

  • Comparing different perspectives on good naming practices
  • Understanding the relationship between names and cognitive processes
  • Exploring the effect of different naming styles
  • Investigating the effect of bad names on bugs and errors
  • Learning how to structure a variable name to maximize understanding

Part 1 covered the different cognitive processes involved in reading code, including storing information in the LTM and retrieving it when needed, storing information in the STM, and processing code in the working memory. In part 2, we looked at how we think about code, what mental models are formed about code, and how we talk about code. In Part 3, we will zoom into the process of writing code rather than reading or thinking about it.

This chapter aims to study how to best name things in code, like variables, classes, and methods. Since we now know quite a bit about how the brain processes code, we can more deeply understand why naming is so important for code comprehension. Good names help activate your LTM to find relevant information you already know about the domain of the code. Bad names, on the other hand, can cause you to make assumptions about the code, leading to misconceptions.

8.1 Why naming matters

8.1.1 Why naming matters

8.1.2 Different perspectives on naming

8.1.3 Initial naming practices have a lasting impact

8.2 Cognitive aspects of naming

8.2.1 Formatting names supports your STM

8.2.2 Clear names help your LTM

8.2.3 Variable names can contain different types of information to help you understand them

8.2.4 When to evaluate the quality of names

8.3 What types of names are easier to understand?

8.3.1. To abbreviate or not to abbreviate?

8.3.2 Snake case or camel case?

8.4 The influence of names on bugs

8.4.1 Code with bad names has more bugs

8.5.1 Name molds