General discussion


Variable names--can they be too short or too long?

By RayJeff ·
Tags: Off Topic
blog root

This conversation is currently closed to new comments.

3 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -


by RayJeff In reply to Variable names--can they ...

The reason I believe my variable names are too long because for one,
they are! Depending on what the variable holds, I make it long. It's
usually the format of what the variable holds and where the variable is
located. For example, If I were to have a variable in a Java applet
that holds a SSN in an employee info form. the variable name might be
"ssnEmployeeInfoForm" with EmployeeInfoForm" being a part of the actual
whole name of the form. This can get very tedious over time. I've read
over many texts and blogs and group posts, etc of "following
established naming conventions" of a particular company, etc. This puts
me at a great debate. I say this because of the current project I've
been working on for the almost two years. I'm working in a division
that had no IT person at all before me, muchless a programmer for me to
be mentored by. Also, there is no one in the college (where I work)
that has ever designed an in-house program/application for use. And the
main part is there is no established naming convention. So, I'm
basically using all of the academic knowing I have and applying it the
best way I can. <br />
<br />
My problem is considering my situation, are my variable names long
enough or too long? Should variable names be as descriptive as they can
be or just brief enough to be ok?  I also remember the lessons
about in the good ol old days of computing when variable names had to
be very short because of writing a program with less than 1 Meg of
memory and only KBs of hard drive space. Totally different from today's
world. So, I want to put this out there to you TechRepublic. I'd like
to hear your opinions.<br />
<br />

Collapse -


by gene.fellner In reply to Continuing....

<p>The "good old days" are apparently not being remembered accurately. In the Cobol era, working on a mainframe with only 64KB of memory, our compilers still allowed us to create datanames up to 32 characters long. And we could go beyond that, because they could be nested. In your example, more than one form might contain a space for SSN. So you could refer to SSN OF EMPLOYEE-INFO or SSN OF PAYROLL-REC. (Geeze, I've forgotten my Cobol vocabulary. I don't know whether OF is the right word, but you get the idea.)</p>
<p>I am a big believer in hierarchical organization. If you look at the hard drive on my Mac, you'll find that most of my file names are fairly short. But my directory structure is deep. I never have trouble finding what I want because the intermediate-level directory names are navigational aids.</p>
<p>If contemporary programming languages don't let you create variable names with one or more qualifiers, it's a great loss. It would also illustrate my thesis that PC software developers deliberately ignore everything we accomplished in the mainframe era because they think it's more fun to make mistakes and then fix them than to actually provide high quality software to their customers.</p>
<p>The next level of OS/X promises to do away with my idea of directories by providing a lightning-fast search engine that can search on content. I wonder whether I'll find myself converting over to that way of thinking. It's pretty foreign to me. I prefer structure and a roadmap to chaos and a really powerful flashlight.</p>

Collapse -


by jmgarvin In reply to Continuing....

<p>There is a balance that you must find.  While naming your variables x sure is tempting, naming them ssn_for_employee_search_function_that_will_return_to_another_function_and_be_reused_in_a_hash is just as bad.</p>
<p>So what should you name your variables?  Something that another programmer can come in and look at and understand what they are doing.  Don't forget you can always comment and explain in detail various stuff about your program.</p>
<p>So, what is the answer?  You should probably be pretty clear with your variable names, but remember you have comments to explain further what each variable is, what it does, and what value(s) are expected out of or into it.  From your example, you could probably shorten the variable to ssn and reuse it other functions that need ssn when needed.</p>

Back to After Hours Forum
3 total posts (Page 1 of 1)  

Related Discussions

Related Forums