• RageAgainstTheRich@lemmy.world
    link
    fedilink
    arrow-up
    1
    ·
    edit-2
    6 months ago

    That is a… strange take.

    Random example, imagine a variable that holds the time of the last time the user moved the mouse. Or in a game holding the current selected target of the player. Or the players gold amount. Or its level. Or health. Or current position.

    • frezik@midwest.social
      link
      fedilink
      arrow-up
      0
      arrow-down
      1
      ·
      6 months ago

      In all those cases, the answer is to swap in a new variable and throw the old one away.

        • frezik@midwest.social
          link
          fedilink
          arrow-up
          1
          ·
          6 months ago

          It’s only a const within a function. You can pass the value to another function and changing it as it’s passed. For example:

          const int foo = 1
          other_func( foo + 1)
          

          In functional programming, you tend to keep track of state on the stack like this.