It is definitely better to have a variable appearing several times than a large expression.
This may not make a difference in efficiency in any case, but from the point of view of the organization of the program it is better not to repeat large blocks of code.
If huge_term is something that the compiler can recognize as a common subexpression whose value does not change between the two evaluations, it can be eliminated using CSE (general subexpression exception). But just because the compiler can reduce this does not mean that this is not a maintenance headache.
How many times a variable appears, hardly anything needs to be disturbed, especially if it helps reduce the repetition of a large expression. That is, if the variable is not a volatile memory cell, such as an I / O port. If assigning a is an externally visible effect, then the two versions do not have the same semantics.
source share