Talk:Variables: Difference between revisions

→‎Constants: A typing issue in my view
(→‎Constants: Include naming conventions on otherwise standard variables?)
(→‎Constants: A typing issue in my view)
 
(One intermediate revision by one other user not shown)
Line 17:
 
:"The things that you use instead of magic numbers" might be a naming convention on otherwise standard variables? --[[User:Paddy3118|Paddy3118]] 18:49, 20 October 2009 (UTC)
::Perhaps I phrased it poorly here. I'm specifically referring to "variables" that aren't variable, i.e. things declared <code>const</code> in C or BASIC, like in my example above. Not just a naming convention, but part of the language. -- [[User:Eriksiers|Eriksiers]] 01:04, 21 October 2009 (UTC)
 
There are two things in it:
 
* a value, denoted in some way, e.g. by a literal, by an identifier (named constant), by a static expression (evaluated at compile time);
* an object, maybe of an immutable subtype.
 
The term "constant" may refer to either. In [[C]] ''const'' is a type modifier that produces an immutable subtype of the type it precedes. When used in declarations it does an immutable object, e.g. the second thing. But the compiler has right to convert it into the first thing, e.g. not to allocate any objects, but use the corresponding value instead, of course when the value is static. This conversion is semantically valid, when object construction and finalization have no semantically "visible" side effects (memory allocation, CPU cycles are semantically "invisible"). The bottom line is that IMO ''const'' belongs to the tasks dealing with types rather than to variables having those type. --[[User:Dmitry-kazakov|Dmitry-kazakov]] 13:56, 22 October 2009 (UTC)