rspec/rules/S2339/description.adoc

11 lines
902 B
Plaintext
Raw Normal View History

2020-06-30 12:48:07 +02:00
Constant members are copied at compile time to the call sites, instead of being fetched at runtime.
2021-02-02 15:02:10 +01:00
2021-01-27 13:42:22 +01:00
As an example, say you have a library with a constant ``++Version++`` member set to ``++1.0++``, and a client application linked to it. This library is then updated and ``++Version++`` is set to ``++2.0++``. Unfortunately, even after the old DLL is replaced by the new one, ``++Version++`` will still be ``++1.0++`` for the client application. In order to see ``++2.0++``, the client application would need to be rebuilt against the new version of the library.
2020-06-30 12:48:07 +02:00
2021-02-02 15:02:10 +01:00
2021-01-27 13:42:22 +01:00
This means that you should use constants to hold values that by definition will never change, such as ``++Zero++``. In practice, those cases are uncommon, and therefore it is generally better to avoid constant members.
2020-06-30 12:48:07 +02:00
2021-02-02 15:02:10 +01:00
2020-06-30 12:48:07 +02:00
This rule only reports issues on public constant fields, which can be reached from outside the defining assembly.