71.7k views
4 votes
Named constants should be used when they serve to improve readability and understanding. T or F

User Donnie
by
5.5k points

2 Answers

2 votes
It's true. T for true
3 votes
The answer is true.

Let's say we are calculating the volume of a grain silo where the the width is a constant, but the height can be changed.

In our code we would calculate the volume using something like:

PI * (WIDTH / 2)^2 * height

The variables in all caps would be named constants. Using them makes the code more readable to other people than if we were to just use their values like:

3.14 * (145.75 / 2)^2 * height




User Allan Pereira
by
6.0k points