2 That’s a good name

 

This chapter covers

  • Names
  • Naming conventions
  • Namespaces

The names that we give to items and concepts help us navigate the world and communicate with everyone else who shares it with us. The idea that names matter is even more important in the world of software development. Programming languages have keywords, grammar, and syntax that are generally a subset of a common, in-use language. In the case of Python, that language is English.

For programming languages, this means we use a prescribed set of keywords, grammar, and syntax to create programs that will ultimately run. Naming elements in those programs, however, is entirely within your control, as you can draw from the rich set of English words and phrases to name the items you create in a program. You can even use strings of nonsense characters if that suits you. But should you?

“There are only two hard things in Computer Science: cache invalidation and naming things.”

The quote is attributed to Phil Karlton, a programmer with Netscape, the developer of the first widely used web browser. Putting aside cache invalidation, you might be thinking, “What’s so hard about naming things?” Let’s find out.

2.1 Names

2.1.1 Naming things

2.1.2 Naming experiment

2.2 Namespaces

2.3 Python namespaces

2.3.1 Built-ins level

2.3.2 Module level

2.3.3 Function level

2.3.4 Namespace scope

2.3.5 Namespace experiment

Summary

sitemap