Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

167
Views
Do same-line references of a variable contribute to its span?

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.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!