McConnell_2004_CH11_The_Power_Of_Variable_Names Flashcards

1
Q

What is McConnell’s most important consideration in naming a variable….?

A

Is that the name fully and accurately describe the entity the variable represents.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What does good mnemonic do?

A

A good mnemonic name generally speaks to the problem rather than the solution. A good name tends to express the what more than the know. In general, if a name refers to some aspect of computing rather than to the problem, it’s a how rather than a what. Avoid such a name in favor of a name that refers to the problem itself.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the optimal length for a variable name?

A

The optimum length for a name seems to be somewhere between the lengths of x and maximumNumberOfPointsInModernOlympics.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

In which situations are short variable names more acceptable?

A

Are short variable names always bad? No, not always. When you give a variable a short name like i, the length itself says something about the variable-namely, that the variable is a scratch value with a limited scope of operation

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is a computed value qualifier and where should it be put in a variable name…?

A

Many programs have variables that contain computed values: totals, averages, maximums, and so on. If you modify a name with a qualifier like Total, Sum, Average, Max, Min, Record, String, or Pointer, put the modifier at the end of the name.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is a loop index variable and how should it be named…?

A

Guidelines for naming variables in loops have arisen because loops are such a common feature of computer programming. The names i, j, and k are customary:

A variable is to be used outside the loop, it should be given a name more meaningful than i, j, or k.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is a status variable and how should it be named…?

A
  • Status variable describe the stat of your program.
  • Think of a better name than flag for status variables: its better to think of flags as status variables. A flag should never have flag in its name because that doesn’t give you any clue about what the flag does. For clarity, flags should be assigned values and their values should be testing with enumerated types, named constants, or global variables that act as named constants.

See page 266 to 277 for examples.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is a temporary variable and how should it be named…?

A
  • Temporary variables are used to hold intermediate results of calculations, as temporary placeholders, and to hold housekeeping values. They are usually called temp, x, or some other vague non-descriptive name.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is Boolean variable and how should it be named?

A

A binary variable, having two possible values called “true” and “false.”.

Examples of Boolean variable names, Done, Error, Found and success or ok.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Discuss the benefits of having variables naming conventions. Illustrate your points by mentioning common Jade variable naming conventions….?

A
  • Some programmers resists standards and conventions- and with good reason. Some standards and conventions are rigid and ineffective destructive to creativity and program quality. This is unfortunate since effective standards are some of the most powerful tools ant your disposal. This section discusses why, when and how you should create your own standards for naming variables.

Conventions offer several benefits:

  • They let you take more for granted. By making one global decision rather than many local ones, you can concentrate on the more important characteristics of the code.
  • They help you transfer knowledge across projects. Similarities in names give you an easier and more confident understanding of what unfamiliar variables are supposed to do.
  • They help you learn code more quickly on a new project. Rather than learning that Anita’s code looks like this, Julia’s like that, and Kristin’s like something else, you can work with a more consistent set of code.
  • They reduce name proliferation. Without naming conventions, you can easily call the same thing by two different names. For example, you might call total points both pointTotal and totalPoints. This might not be confusing to you when you write the code, but can be enormously confusing to a new programmer who reads it later.
  • They compensate for language weakness. You can use conventions to emulate named constants and enumerated types. The conventions can differentiate among local, class, and global data and can incorporate type information for types that aren’t supported by the compiler.
  • They emphasize among related items. If you use object data, the compiler takes care of this automatically. If your language doesn’t support objects, you can supplement it with a naming convention. Names like address, phone, and name don’t indicate that the variables are related. But suppose you decide that all employee-data variables should begin with an Employee prefix, employeeAddress, employeePhone, and employeeName leave no doubt that the variables are related. Programming conventions can make up for the weakness of the language you’re using.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly