Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
bellrd1224y
-
C0D4681384y@bellrd oh, you're applying the English language to programming. You will go crazy since neither respected each other here.
-
Constants and variables are two separate concepts. If someone is talking to you about "constant variables," you should be smiling, nodding and piping everything they say to /dev/null
-
@C0D4
Dunno, just got back from a riot, I'll let you know after I finish trying on my new jackets. -
C0D4681384y@SortOfTested ooh nice new leather jacket? At least you got something worth while out the riots.
-
hitko31484yLet's say you have
for(i = 0; i < a.length; i++) {
const item = a[i];
...
}
Is "item" constant? Sure, you can't reassign it within its scope. But then, "item" will have many different values as the program executes, so it's still kinda variable.
On the other hand, const window = 5; will always have the same value as defined at compile time. -
You didn't specify the language. In C, "const" does not mean "constant". It means that you won't write to that variable programmatically. That has several uses:
1) Function arguments with pointers to const variables: the compiler knows you won't change the underlying memory and can do more optimisation. Fellow devs know already from the function signature that there's no manipulation, which is helpful when getting into a foreign codebase.
2) Variables can even be "const" and still change, usually paired with "volatile". That would be e.g. read-only registers that change in hardware, like status or receive data registers. Marking these as "const" makes sure that nobody tries writing to them, and it conveys their purpose.
3) In embedded systems (microcontrollers), the linker can put global "const" variables (e.g. lookup tables) into the ROM instead of the RAM. This is useful because there's typically much more ROM than RAM.
4) "const" variables are still typed (unlike defines). -
In day to day language, most people say "variable" when they mean some identifier where a value is stored and can be referred to in the code.
Then they apply "constant" to it to say that the value can not change.
It's technically not correct but come on, it's understandable.
What the fuck is constant variable
Variable (changing) but its constant.
rant