The Nuts and Bolts

The following sections investigate how to name each category of item we listed earlier. Even if you’ve been programming for years, this is a useful review of the broad spectrum of naming conventions.

Naming Variables

If a variable wasn’t just an electronic entity, it would be the sort of thing you could hold in your hand, the software equivalent of a physical object. A name that reflects this will usually be a noun. For example, variable names in a GUI application might be ok_button and main_window. Even variables that don’t correspond to Real World objects can be given noun names; consider elapsed_time or exchange_rate.

If not a noun, a variable will usually be a “noun-ized” verb, for example, count. A numeric variable’s name ...

Get Code Craft now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.