Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

158
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda