If this is not a right place to post this article, please move it to another way,
thank you very much.

Sometimes(or always) giving a name to a class or variable is not an easy job, I want
to make it expressive and short, how do you solve this kind of problem? Although
this may not a big problem at the beginning, but when the project become bigger and
bigger, I find out that good name of class and variable could be useful, a good
name could make the program easier to read, less ambiguity, and it could be more
expressive than a lot of comments.

Recommended Answers

All 3 Replies

The idea of a "short" variable name only made sense when memory was very expemsive and the maximum was only 640K RAM.
Giving it a meaningfull name is more important and helps with self-documenting e.g.

int lstr_this_variable_will_only_be_used_under_certain_conditions;

makes more sense than

int maybe;

The idea of a "short" variable name only made sense when memory was very expemsive and the maximum was only 640K RAM.

Um, no. The idea of a "short" variable name still makes sense because names that are too long are still hard to type and still tend to obscure the structure of the code. This crap about memory is silly because the variable name goes away during compilation. Memory usage for variable names only goes as far as the text editor.

It's a matter of common sense and context. i may be a perfectly suitable name for a temporary loop counter, but woefully inadequate for a global. On the other hand, lstr_this_variable_will_only_be_used_under_certain_conditions is way too long and should be shortened. If there's no way to shorten the name, then the variable does too much and should be refactored. maybe could also be fine depending on the context.

Looks like there are no silver bullet for this kind of problem
Anyway, thanks for your suggestions.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.