Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

On Naming Variables

Status
Not open for further replies.

Galford

Programmer
Jan 5, 2001
13
0
0
US
I wanted to know if giving variables and procedures long descriptive names slows down a program in runtime mode?

Thanks
 
No it doesn't. The compiler removes the names and replaces them with a reference to a memory location. So no matter how big or small the name is, it still resolves to a memory location once it's compiled.

If you're running in the IDE or you compile your code with Symbolic Debug Info, it might have a slight effect. But I can't say for sure.

From the VB-Helper site:

Use comments and meaningful variable names. Long comments and variable names, and blank lines do not add to the compiled program's size so there is no harm in using them.

Here's some good performance techniques to use. The line above was taken from the link below:

Snaggs
tribesaddict@swbell.net
There are two kinds of people in life: people who like their jobs, and people who don't work here anymore.
 
Snaggs -

Isn't there some upper limit on variable name length? I seem to recall 32 as being the max, but that might have been in VB4 or something.

Of course, if your variable names are that long, your fingers will get a real workout typing them!

Chip H.
 
I think it's 64. Here's something interesting I found rooting around for the answer.

The amount of code that can be loaded into a form, class, or standard module is limited to 65,534 lines. A single line of code can consist of up to 1023 bytes. Up to 256 blank spaces can precede the actual text on a single line, and no more than twenty-five line-continuation characters ( _) can be included in a single logical line. Snaggs
tribesaddict@swbell.net
There are two kinds of people in life: people who like their jobs, and people who don't work here anymore.
 

I had heard about the 64k limit on number of lines, but didn't know about the continuation limit. Cool stuff!

Chip H.
 
Variable names in Visual Basic can be no longer than 255 characters, and the names of forms, controls, modules, and classes cannot be longer than 40 characters. Visual Basic imposes no limit on the actual number of distinct objects in a project.

These and other specifications or limitations can be found at:


_________________________________
In theory, there is no difference between theory and practice. In practice, there is. [attributed to Yogi Berra]
 
Thanks for the replys and the links. They helped alot. I loved the performance page on vb helper. Lots of stuff I didn't know.
 
From the above comments it should be clear that using long variable names is OK to do. Moreover, it is reccomended since someone debugging later will have a better chance of figuring out what is going on. The only issue has to do with spelling errors. When using long variable names, it may become an issue. The longer the variable, the more likely you or someone else will misspell. Joseph Logan
Softsource, Inc.
Software Engineer
jlogan@softsource.net
 
RE: misspelling variables. As long as you always "Require Variable Declarations" by including Option Explicit in the Gen Declarations section of every module, misspelling variable names becomes a very minor problem. Each one is flagged as a compile error as soon as it's encountered.

"Option Explicit" keeps many a headache from ever occuring!
 
Right-on, Andy!

First thing you should do after installing VB is set the "Require Variable Declaration" flag on. I think that Microsoft did a big disservice to VB programmers by shipping VB with it turned off.

Chip H.
 
Descriptive variable names will be more effective if you stick to certain standards such as Hungarian notation or a consistent style in your names like consistent Noun-Verb order such as RecordAdd, InterestCalc, ParametersSet.

You may prefer Verb-Noun order e.g. AddRecord, CalcInterest, SetParameters.

One annoying aspect I find in coding is trying to remember the exact spelling of my variables and I often have to browse through the code to get it right. Following a consistent style helps me to deduce the correct name without having to look it up.

 
Microsoft is strange. If it limited control names to 40 characters, why did it limit control property names to 30 characters?

Not that I try to come up with long, descriptive control property names very often... I just find it perplexing that Microsoft was able to find yet another way to yank my chain.

:)
VCA.gif

Alt255@Vorpalcom.Intranets.com

"If you can get people to ask the wrong questions, they'll never find the right answers."[tt]
Thomas Pynchon[/tt]

Perhaps the reverse is also true....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top