Chapter 3: What’s in a Name?
Mull It Over
Are these good variable names? Answer with either yes (explain why, and in what context), no (explain why), or can’t tell (explain why).
int apple_count
char foo
bool apple_count
char *string
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 ...
Get Code Craft now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.