←back to thread

498 points azhenley | 1 comments | | HN request time: 0.232s | source
Show context
anymouse123456 ◴[] No.45771965[source]
I completely agree with the assertion and the benefits that ensue, but my attention is always snagged by the nomenclature.

I know there are alternate names available to us, but even in the context of this very conversation (and headline), the thing is being called a "variable."

What is a "variable" if not something that varies?

replies(14): >>45772017 #>>45772042 #>>45772062 #>>45772077 #>>45772262 #>>45772625 #>>45773368 #>>45773945 #>>45774039 #>>45775594 #>>45775669 #>>45775698 #>>45775911 #>>45776839 #
1. layer8 ◴[] No.45775698[source]
Variables are called variables because their values can vary between one execution of the code and the next. This is no different for immutable variables. A non-variable, aka a constant, would be something that has the same value in all executions.

Example:

  function circumference(radius)
      return 2 * PI * radius
Here PI is a constant, while radius is a variable. This is independent of whether radius is immutable or not.

It doesn’t have to be a function parameter. If you read external input into a variable, or assign to it the result of calling a non-pure function, or of calling even a pure function but passing non-constant expressions as arguments to it, then the resulting value will in general also vary between executions of that code.

Note how the term “variable” is used for placeholders in mathematical formulas, despite no mutability going on there. Computer science adopted that term from math.

https://en.wikipedia.org/wiki/Variable_(mathematics)