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

From Expertiza_Wiki
Jump to navigation Jump to search
Line 17: Line 17:
===Keep Names Short and to the Point===
===Keep Names Short and to the Point===


===Use Descriptive Names===
===Be Descriptive===


===Explain Abbreviations with a Comment===
===Explain Abbreviations with a Comment===

Revision as of 03:33, 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

Be Descriptive

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 Be Generic

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.