• marcos@lemmy.world
        link
        fedilink
        arrow-up
        15
        arrow-down
        3
        ·
        1 year ago

        There’s no ISO standardized definition for variable. People use that word with all kinds of meaning.

        • drcouzelis@lemmy.zip
          link
          fedilink
          English
          arrow-up
          16
          ·
          1 year ago

          Waaaait a minute… isn’t it called a variable because the contents are, you know, variable?

        • Yen@feddit.uk
          link
          fedilink
          arrow-up
          11
          ·
          1 year ago

          This is needlessly obtuse. The definition of the word is that it’s non-constant. There isn’t an ISO definition of the word no, but there are many reputable dictionaries out there that will serve as an alternative.

      • Walnut356@programming.dev
        link
        fedilink
        arrow-up
        4
        ·
        edit-2
        1 year ago

        I feel like it’s like pointers.

        “Variable” refers to the label, i.e. a box that can contain anything (like *ptr is a pointer to [something we dont know anything about])

        Immutable describes the contents, i.e. the stuff in the box cant change. (like int* ptr describes that the pointer points to an int)

        Rust makes it very obvious that there’s a difference between constants and immutable variables, mainly because constants must be compile time constants.

        What do you call it when a variable cant change after its definition, but isnt guaranteed to be the same on each function call? (E.g. x is an array that’s passed in, and we’re just checking if element y exists)

        It’s not a constant, the contents of that label are “changing”, but the label’s contents cant be modified inside the scope of that function. So it’s a variable, but immutable.

    • Eufalconimorph@discuss.tchncs.de
      link
      fedilink
      arrow-up
      2
      ·
      1 year ago

      And more generally mutable aliasing references of any sort are evil. Doesn’t mean they’re not useful, just that you need magic protection spells (mutexes, semaphores, fancy lock-free algorithms, atomics, etc) to use them safely. Skip the spell or use she wrong one, and the demon escapes and destroys all you hold dear.