CQM-ConstantsRain

Global constants should have unique names

Required inputs: IR

There must not be more than one global constant with the same name in the system.

Motivation

Global constants are constants declared for use in many different places in the system. Since a large number of constants are usually necessary in large systems, a dedicated constant concept is required.

In any case, it should be avoided that globally visible constants occur several times by name, since otherwise different contents can be addressed with the same name. At any rate, with a constants rain there is the danger that a retrieval, adjustment and change of a special constant is possible only with large time expenditure. If these redundant constants have different values, the functionality is probably also endangered. A change of a constant value must then be repeated possibly at several other places. If a place is forgotten, the behavior of the program gets possibly out of control.

This rule is based on the CQM Quality Indicator: Konstantenregen (p. 234-236).

Reference

Simon, Frank/ Seng, Olaf/ Mohaupt, Thomas (2006): Code-Quality-Management: Technische Qualität industrieller Softwaresysteme transparent und vergleichbar gemacht, 1st ed., Heidelberg, Germany: dpunkt.verlag GmbH.

Possible Messages

Key

Text

Severity

Disabled

reused_global_variable_name

Name of constant with static storage duration reused.

None

False

Options

allow_static_no_linkage

allow_static_no_linkage : bool = False

Whether to allow same identifiers for static objects without linkage (e.g. function local static objects).
 

include_local_variables

include_local_variables : bool = True

Whether local static variables should be included in the check.
 

use_unqualified_names

use_unqualified_names : bool = True

If set to true, ns1::Type is considered equal to ns2::Type.
 

var_filter

var_filter : typing.Callable[[Variable], bool] | None = <function bauhaus.rules.cqm.rules.constants_rain._filter_const(node: Variable) -> bool>

Restricts which variables are considered.