CSC/ECE 517 Fall 2010/ch5 5b jz: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
(Added rough outline)
Line 29: Line 29:
===Use Units in Names===
===Use Units in Names===


===Avoid Negative Logic in Names===
===Avoid Negative Logic===


Always use positive logic when naming variables, especially in the case of boolean values. Using a name such as 'isNotEnabled' instead of 'isEnabled' only serves to confuse yourself and any future readers of the code.
Always use positive logic when naming variables, especially in the case of boolean values. Using a name such as 'isNotEnabled' instead of 'isEnabled' only serves to confuse yourself and any future readers of the code.

Revision as of 03:32, 2 November 2010

Variable Naming Conventions

Importance of Good Variable Names

Variable Naming History

General Guidelines

Use a Common Naming Scheme

Hungarian Notation

Under Scores

Camel Case

Keep Names Short and to the Point

Use Descriptive Names

Explain Abbreviations with a Comment

The last two points would seem to contradict each other, but having short and to the point names does not necessarily mean that they are less descriptive. In fact, many variable names can be shortened with the use of abbreviations to make them not only descriptive, but succinct as well. Just remember to explain any abbreviations that you have made in a comment that accompanies the declaration of the variable.

Don't Use Generic Variable Names

Variables such as 'temp' or 'counter' may seem self-explanatory when first writing a block of code, but they quickly lose their meanings when re-reading that same code out of context. Avoid using generic names such as these.

Use Units in Names

Avoid Negative Logic

Always use positive logic when naming variables, especially in the case of boolean values. Using a name such as 'isNotEnabled' instead of 'isEnabled' only serves to confuse yourself and any future readers of the code.