For C ++,
$ cat name.cpp int main() { int a = 74678; int bcdefghijklmnopqrstuvwxyz = 5664; } $ g++ -S name.cpp $ cat name.s .file "name.cpp" .text .align 2 .globl main .type main, @function main: .LFB2: pushl %ebp .LCFI0: movl %esp, %ebp .LCFI1: subl $8, %esp .LCFI2: andl $-16, %esp movl $0, %eax addl $15, %eax addl $15, %eax shrl $4, %eax sall $4, %eax subl %eax, %esp movl $74678, -4(%ebp) movl $5664, -8(%ebp) movl $0, %eax leave ret .LFE2: .size main, .-main .section .note.GNU-stack,"",@progbits .ident "GCC: (GNU) 3.4.6 20060404 (Red Hat 3.4.6-11.0.1)" $
As you can see, neither a nor bcdefghijklmnopqrstuvwxyz reflect assembly output. Thus, the length of the variable name does not matter at runtime in terms of memory.
But variable names are huge contributions to program design. Some programmers even rely on good naming conventions instead of comments to explain the design of their program.
Corresponding quote from Hacker News ,
The code should be written in such a way as to fully describe the functionality of the program for readers for humans and only be randomly interpreted on computers. It is not easy for us to remember short names for a long time, and it is difficult for us to look at long names again and again in a row. In addition, short names have a higher chance of collisions (since the search space is smaller), but they are easier to keep for short reading periods.
Therefore, our conventions for naming things must take into account the limitations of the human brain. The length of the variable name must be proportional to the distance between its definition and its use and inversely proportional to the frequency of use.
Lazer
source share