'''''Always, always, always use good, unabbreviated, correctly-spelled meaningful names.''''' '''Rationale''' It's clearer, easier to read. You aren't forced to remember the exact spelling of a symbol because you always know it is spelt correctly and thus consistently. It's also easier to search for with an editor's search function - try searching or grepping for all occurrences of the variable "i" within a function, without also picking up every instance of "void", "int", "printf", etc. You can do it with RegularExpression''''''s, but not all editors have regex searches. It's statistically shown that using longer names leads to shorter debugging times, according to ''201 Principles of Software Design.'' A MeaningfulName gives you the ability to understand code two years after it is written. Unless you are using Fortran or an archaic C compiler and have to worry about the six-character limit on external symbols, there is no reason to use abbreviations. Disambiguation: See also a paper by the same name at http://tottinge.blogsome.com/meaningfulnames/ '''Arguments''' ''"This is a mere platitude"'' The rule does not help me choose between reasonable alternatives, it only tells me not to write bad, abbreviated, incorrectly-spelled meaningless names. Apart from the abbreviated or not question, why would I choose to do the other? ''"I don't like typing that much!"'' Good editors help. Copy and paste if you have to. It's not really that much to do. Typically, in a narrow system, a given symbol won't be referenced more than 20 times anyway. ''"It's difficult to come up with meaningful names!"'' Agreed. However I find that if I'm struggling to name something (be it local variable, object, pattern, ...) it is a sure sign I don't ''really'' understand what's going on. I also tend to think that bad names help to highlight areas where the CodeSmell''''''s. NonMeaningfulNames can also be a sign of OverAbstraction, or the fact that you, the reader, aren't literate in the program's ProblemDomain. Disagree. If you have a good understanding of the problem domain, producing meaningful names becomes easy. ''"Our simple, meaningful names tend to collide with third parties."'' Use namespaces, scoped names, name mangling, or a large club to beat them with. ''"I speak not good English and nobody in the my team does good. So we call method like getChilds() and getConcreteHead()"'' ''"Short names make it easier to see the overall pattern of what is going on!"'' Long names LoseSignalInNoise. (Being discussed below.) '''Exceptions''' Abbreviations that have been used so often they have become words themselves. Such as the common mathematical functions min, max, sin, cos, abs; (although mathematics is a horror story in itself). ''This is just a special case of another rule: Use term from the domain where appropriate. If your customer understands what an ni_rim is, use that.'' '''Examples''' "Sch" does not mean "Schedule". It means someone was too lazy to type the extra five characters and that probably means the rest of the code is equally as lax. It is contentious whether or not "i" is the same as "count". "count" is probably just as bad as "i". "iStringPosition" may be better, but symbols that long tend to ''decrease'' readability of string parsing algorithms and simple iterations. * Count can have a domain-specific meaning whereas "i" is meaningful across all domains. You know it is always the index inside a for loop. Since it cannot have any real meaning, assigning it any name would detract and take an extra step of information processing to the code reader. On the other hand, functional programming (C++'s STL supports this, although STL isn't necessarily supported by your compiler yet), removes even this case. ---- I think obscure abbreviated variable names are hard to use if they are hard to remember, otherwise, almost everything above is ''bad programming practice''. Variable names aren't comments. If you think the variable needs more than the name you call it, then put the extra description in a comment. Why is it that almost all Mathematical formulas just use a, b, c or x, y, and z as variable names? Because the point is the relationship between them rather than what they are. Sometimes a table is given to explain what each of the variables mean. Almost all variables are local to a function, a table or an object. In all those cases, you only have to have unique names within that scope which doesn't require more than a single word. The more typing you do, the more chance of spelling the variable wrong. Long variable names also detract from the readability of a program and the longer names, in general, don't add any more explicit meaning than smaller variable names. I think there is a place for 1 character variable names but I am mostly saying that variables should be 1 word in size. I don't believe for 1 second that large variable names make debugging code easier. It is just not true. Having a good data dictionary and reusing the same variable names in different contexts makes program code easier to work with and less error prone. Encoding the variable type as a postfix or prefix of the variable name is also bad. If you don't know what type of variable it is ''don't touch it''. -- DavidClarkd ---- ''NomenEstOmen'' is Latin for "the name says it all" or maybe "take the name as a sign" For OO programming that means that a class "Manager" is likely to not doing something productive. See: DoesWhatItSaysOnTheTin, RonsealPattern ---- '''But''' Abbreviations are bad, but much better than omitting information totally. So a function "copy" (unabbreviated word) is unacceptable compared to "F''''''ileCpyUrl" (abbreviated words). Omitting a word should be considered identical to abbreviating it to length zero. See also: LanguageOrientedProgramming, ThelopLanguage, ThelopDictionary -- HelmutLeitner "F''''''ileCpyUrl" is still a ''terrible'' name, hardly better than "copy" at all. Does it copy data from a file to a URL, or copy data from a URL into a local file? And why "Cpy" not "Copy". Is ''one'' character going to make that much difference? ---- Examples of MeaningfulName''''''s are: * Account''''''Number * Speed''''''Of''''''Light * Radius Some not so meaningful names for the above would be: * Act''''''No - Activity Number, Account Number? * C - The programming language, a well known constant? * R - Rate of Return, Radius? --Kris Wenzel ---- In practice I have found that FullySpellingOutAllWordsInCompoundVariableNames can easily lead to excessively long names, such that even simple expressions, like "x = y + 1" won't fit in an 80-character line (after a few 4-character indents). Yes, refactoring things into micro-modules helps, but (to some extent) it trades one form of complexity for another. -- JeffGrigg ''Excessively long lines are a CodeSmell. Assign state to variables in such a way that the contents of each variable may be described more succinctly.'' The principle here should be that the length of a name must vary proportionately to its scope. I don't think that "i" is so bad in a list comp, or a loop counter inside a small method, but it is entirely wrong for a parameter name of a public function (or a private one, for that matter). Perhaps this is a matter of "dealing with a matter where the matter matters". I tend to use better variable names outside of list comps, where they can be seen, but in an anonymous or inner-nested function it is sometimes of little consequence. That being said, long lines are a code smell as are confusing names. --TimOttinger ---- '''Meaningful to whom?''' activateModem, initializeModem, makeModemReadyForUse, prepareModem, modemPrep, setupModem, setInitialModemState, executeModemPreparationSequence, ad nauseum ... none of these says more to me than modemInit. The programmer making up the names may see things through very different eyes from those of the later programmers. Passive voice as opposed to active voice. Odd choices of adjectives. And when one of the guys is from Thailand and creates function names like settingAllModemInsideRegisterForBeginValue and variables like wasStatusForToDialFinal (and, really, I'm not doing him justice -- some of his names were truly breathtaking) you can become a poster child for asprin. Wait, wait, it gets better ... how about module name prefixing: customerModuleRetrieveFirstFitSpaceRecordSet among a set of functions that all begin with customerModuleRetrieve ... oh, man. You know, I was okay until I started to recall that nightmare. Andy, wherever you are, I hope you've opened a restaurant or something. Keep names short. Code to a convention. Yes, make them meaningful. No, dontTryToWriteWholeSentencesWithYourStinkingFunctionName! ''Let's make an exception to that rule for testing. TestThatTheParserDealsWithExtraneousLeadingWhitespace() is not a problem. It's a solution.'' -- TimOttinger ''I wonder if the tendency for South Asian cultures to have long names (both in individual parts and number of parts) was part of this Thai programmers motivation?'' Probably. CulturalAssumptions have a huge effect on name choices. Grammar probably also plays a large part; Thai does not have a rich, specific vocabulary for technical concepts. As a result, it tends (like German) to use a lot of highly verbose language to describe fairly commonplace technical things. Since culture plays such a huge part in such tendencies, it can be extremely difficult for programmers to conform to a Western/American methodology. ---- '' 3 Choose a name that describes WHAT the object does, not how it does it.'' ''-- TomStambaugh'' ---- I find that if I'm struggling to name something (be it local variable, object, pattern, ...) it is a sure sign I don't ''really'' understand what's going on. I also tend to think that bad names help to highlight areas where the CodeSmell''''''s. NonMeaningfulNames can also be a sign of OverAbstraction, or the fact that you, the reader, aren't literate in the program's ProblemDomain. I would add checking a prospective employee's naming conventions to the GuerrillaGuideToInterviewing as an easy way to immediately flag someone as a NoHire. -- DanGreen ---- I added "but short names make it easier to see the pattern of what is going on." I have a general rule: The more frequently a name is used, the shorter it should be. ''Codified in CodeComplete, by the way -- JeffBay'' "index" is so common, and frequently so semantically unimportant, it can be abbreviated to "i" and make code easier to read. for(int i=0;i