I have a question about the variable "span" metric.
I'm planning on writing a program in JavaScript that parses some JS and returns the span or live time of a variable. I learned about those two metrics after reading Clean Code by Steve McConnell. That means I've chosen to rely on his definition of them. (In that article, the relevant text is under the "Scope" header.)
Example:
let a = 3;
let b = 0;
b = 2;
a = 1;
So a's span here would be 2, and b's span would be 0.
I'm trying to understand whether if a variable is mentioned twice on the same line, do I use the second reference on the same line in my calculation? Or do I only increment by 1 for every 1+ references to a line?
I assume the point of factoring that into span is because it could represent that you're using too many references to the same variable on one line or something?
Example:
let a = 0;
a = a + a
So would that mean that the average span for the above example would be (1 + 0 + 0) / 3? The denominator would increase if I added the multiple references per line to my calculation so the number would definitely change.
McConnell said that
"to [measure] how close together the references to a variable are," you check how many "lines come between the first reference to [it] and the second."
Sergey Kalinichenko said that
"the declaration and initialization happen on the same line, meaning that the line of the declaration should be considered the first use of the variable."
However, I think he was talking about whether declaration counts as the start of live time.