Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

159
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda