Does the name size of a variable affect your weight?

Asked

Viewed 225 times

12

There’s a size difference between that:

string packet1234 = "123";

And that?

string packert1234556 = "123";
  • 4

    Luck that does not affect, otherwise the Java people would be chipped.

  • Not to mention some from the Oracle ...

1 answer

14


No, definitely not. Actually after compiling the code the variable name is gone. A variable is just a well-known design pattern to facilitate access to a memory address. In compiled languages the name becomes direct addresses. It is a convenience of access to memory used in high-level spoken languages. They are used to facilitate the programmer’s understanding of the code. Therefore, their names should be significant.

Only in languages fully interpreted, which are quite rare, is that it could make some measurable difference. But this last word is key. Because it could measure but it wouldn’t really make a difference. And this in interpreted languages that don’t have any kind of optimization. I put this more to the point of curiosity, it does not affect at all the C# that is compiled.

So in any language I know the size of the variable name will not affect the performance or memory consumption significantly and in most cases not even minimally. The choice of name should already be made thinking about readability even if there was some cost to big names.

There is even a memory cost in C# in certain situations where the variable name is not a common local variable, since C# has several metadata. Then a larger name would bring a more theoretical consumption. But it’s such a tiny difference in its definition and not in its consumption that it would be ridiculous to think that this changes anything. It would be like complaining that a drop of rain fell when you are inside a pool (without exaggeration). I put it to give the most correct answer possible but it is even afraid there is an interpretation that there is an extra cost that should be minimally considered. There are so many other factors that affect the program that thinking about it is absurd.

And if by chance the concern makes any sense it is better to program in Assembly. You’d better be mad at this so you don’t make code worse than a good compiler in an optimized language would. Still I doubt it would make sense.

  • 1

    Very enlightened, thank you!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.