From my understanding, a constant is a value which is assigned only once and cannot change at runtime, whereas variables have mutable values which are unpredictable by nature.
My question is, to what extent can it be said that a value is known? Can values which are only assigned once but have some intrinsic "randomness" to them — for example, a UUID which is only set once per process, ever be called constant? Does any form of randomness disqualify something as a constant, even if the assigned value follows a completely predictable pattern?
This is a rather silly semantic question, but I found clashing opinions in other accepted answers while researching this topic [link]:
Variables are not called variables because their values may be changed, but because their value isn't known in advance – when writing the code, they are placeholders for values that will be determined later. In contrast, the value of a constant is known when the program is written.
A constant, in any programming language, is an identifier whose value is not meant to be changed once it is set. It does not matter when this value is learned so long as the constant can not be accessed with anything but this one value.
I take "it does not matter when this value is learned" to imply that it could apply to a mutable value generated at runtime, so long as that value is immutable throughout the program's execution (such as the UUID example).
For the purpose of facilitating comprehension by others, is it always bad practice to flag a pseudo-random integer as a constant by writing it in upper-case? Particularly in languages that don't define a constant
type to begin with (e.g. Python), is it detrimental to do so?