...
Code Block | ||
---|---|---|
| ||
double area(double radius) { return 4.0*Math.PI*radius*radius; } double volume(double radius) { return 4.0/3.0*Math.PI*radius*radius*radius; } double greatCircleCircumference(double radius) { return 2*Math.PI*radius; } |
Exceptions
*EX1:* The use of symbolic constants should be restricted to cases where they improve the readability and maintainability of the code. Using them when the intent of the literal is obvious, or where the literal is not likely to change, can impair code readability. In the Compliant Solution above, the values 4.0 and 3.0 in the volume calculation are clearly scaling factors used to calculate the circle volume, and as such are not subject to change (unlike pi
, they can be represented exactly; there is no reason to change them to increase precision). Hence, replacing them with symbolic constants would be inappropriate.
...