O'Reilly logo

Code Craft by Pete Goodliffe

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 3: What’s in a Name?

Mull It Over

  1. Are these good variable names? Answer with either yes (explain why, and in what context), no (explain why), or can't tell (explain why).

    1. int apple_count

    2. char foo

    3. bool apple_count

    4. char *string

    5. int loop_counter

The quality of a name depends on its context, and we can't honestly tell whether any of these are good or bad names. That's why the question asks for example contexts. There are some obvious contexts where the names might be bad: apple_count wouldn't be a particularly good name for a grapefruit counter.

foo is never a good name. I've yet to see anyone counting foos. loop_counter is also bad; even if a loop gets too big for a short counter name, you can still pick a more descriptive name, one that reflects ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required