4
bellrd
4y

What the fuck is constant variable
Variable (changing) but its constant.

Comments
  • 5
    What are you even saying?
  • 5
    Example, or I'm a thinking you gone crazy.
  • 3
    @C0D4 semantic meaning of variable is something that varying

    But think about constant variable.
  • 9
    @bellrd oh, you're applying the English language to programming. You will go crazy since neither respected each other here.
  • 4
    @C0D4
    But, fucking magnets, how do they work? 😝
  • 5
    @SortOfTested the magnets or the fucking of magnets?
  • 8
    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
  • 2
    @C0D4
    Dunno, just got back from a riot, I'll let you know after I finish trying on my new jackets.
  • 2
    @SortOfTested ooh nice new leather jacket? At least you got something worth while out the riots.
  • 0
    @C0D4
    Nah, over here it's all "a hike can break out at any minute" chic.
  • 0
    Let'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.
  • 6
    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).
  • 0
    Things only non functional programmers think are debatable
  • 0
    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.
  • 1
    @Jilano Cool classic biker leather jackets are badass.
  • 1
    Cries in public static final
Add Comment