0

In programming or mathematics, a variable can take any value.

Due to some reason, now I have to determine a variable to a specific value, say 3.14, and users/callers cannot freely change it.

How would I describe this?

"I fix the variable pi to 3.14"?

It sounds like to me that pi had something wrong, for example pi was 3.13, a typo, and I have to repair to 3.14.

Besides, "fix" has too many meanings.

"I pin the variable pi to 3.14"?

I feel pin fits the context. https://www.oxfordlearnersdictionaries.com/definition/english/pin_2

  • to attach something onto another thing
  • to make somebody unable to move by holding them or pressing them against something

But I searched StackOverflow, people seem not to say "pin a variable".

"I freeze the variable pi to 3.14"?

Are there any better word choices?

When you read "fix a to b", do you feel a had something wrong?

How do I say to express giving a definite value/choice to a variable/possibilities in math or physics? The answer is to use fix or set, but the context is a bit different. In that question, it just so happens that I choose Lorentz frame to evaluate the problem. It's ok to use other frames. But in my context, although there is a blank, I must fill in Lorentz frame, otherwise it will cause catastrophic failure.

2
  • 2
    You set a variable (in a programming context) to a value. If it previously had a different value, you might alter, reset, or amend it to some new value. But if the value of the variable was "fixed" (it's only supposed to contain one value that can't be altered) then it's not really a "variable" at all - so you should probably be looking for the keyword const or equivalent in your chosen development language. Dec 24, 2021 at 16:33
  • @FumbleFingers In some environments there is no mechanism to have a named value that cannot change, all named values are true variables. In others it is possible to have a variable that becomes effectively a constant during program execution, or during a debug session only. Dec 24, 2021 at 16:52

1 Answer 1

3

If one is merely assigning a value to a variable, in my experience the most common verb is "set", as in "I set the variable P to the value 3.14". I would not use the term "repair" for simply changing the value of a variable.

If one is somehow constraining the variable so that it can no longer vary, the favored term will depend on the environment. some programming environments do not have any mechanism to do that. Those that do may each have a specific term for this action. If speaking in general I would favor the term "Lock".

"Fix" would be possible but is IMO too easily confused with the meaning of "correct". The term "pin" might also be used for this purpose, but I don't think i have ever encountered this usage in over 30 years as a professional programmer and software developer. The term "freeze" would be possible, but seems rarwe in my experience. The term "hold constant" I have encountered a few times.

This question reminds me of a maxim from a programming test many years ago:

Constants aren't; variables won't.

2
  • I like lock. Thanks
    – Gqqnbig
    Dec 24, 2021 at 16:42
  • I would expect "fix" in something like a math paper rather than in the programming context. In neither case is "repair" appropriate. Dec 24, 2021 at 20:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .