Sunday 20 November 2011

Do longer variable names affect the speed, executable size, or efficiency of a program? in C programming

Do longer variable names affect the speed, executable size, or efficiency of a program?

No. When you compile your program, each variable and function name is converted to a “symbol”—that is, a smaller, symbolic representation of the original function. So, whether you have a function named

PrintOutAllOfTheClientsMonthEndReports();
or
prt_rpts();

the results are the same. Generally, you should use descriptive function and variable names so that your programs will be more readable. Check your compiler’s documentation to see how many characters of significance are allowed—most ANSI compilers allow at least 31 characters of significance. In other words, only the first 31 characters of a variable or function name are checked for their uniqueness—the rest of the characters are ignored.

A good rule of thumb is to make your function and variable names read just like the English language, as if  you were reading a book. You should be able to read the function or variable name and easily recognize it and know generally what its function is.

Cross Reference:

XIX.1: Should the underscore be used in variable names?
XIX.2: Can a variable’s name be used to indicate its data type?
XIX.3: Does the use of comments affect program speed, executable size, or efficiency?
XIX.4: Does the use of white space affect program speed, executable size, or efficiency?
XIX.5: What is camel notation?
XIX.9: How many letters long should variable names be? What is the ANSI standard for significance?
XIX.10: What is Hungarian notation, and should I use it?

No comments:

Post a Comment