V
V
Vladislav Savin2016-12-12 00:26:56
Programming
Vladislav Savin, 2016-12-12 00:26:56

Why are variables so rarely reused in programs?

The question in the header _________________________________________________________

Answer the question

In order to leave comments, you need to log in

4 answer(s)
V
Vitaly Stolyarov, 2016-12-12
@SavinTop

Probably the question is why not use the already allocated memory for a variable of the type we need, rather than re-allocate it for a new variable to reduce the program execution time?
In high-level languages, variables are designed to fulfill each of their roles. otherwise, constructions of the form

int i=0;

for(;i<4;i++)
dosmth(i);

for(;i<7;i++)
dosmth(i);

not only complicate the readability of the code, but also increase the chance of bugs

P
Pavel Mikhalovsky, 2016-12-12
@pavel9609

What do you think is rare?
If you used the variable once and that's it, then perhaps the variable is needed only once or you have bad code in front of you.

R
Rou1997, 2016-12-12
@Rou1997

After compilation in Assembler, they are reused with might and main, because even in virtual machines (C #, Java) the number of registers is limited. :)
But when writing code, they don’t do this, otherwise there will be confusion, it’s inconvenient to delete and add sections.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question