req a request or a requisition?
res a response, a reservation, a resume, or a result?
def a default or a definition?
rng a range or a random number generator?
v1 version 1 or value 1?
e an event, an entity, or an exception?
f a file or a float?
lst a list or the least value?
temp a temporary variable or a temperature reading?
rep a representation, a representative, a repetition, or a reputation?
tm a time or a trademark? Or even another temporary variable? And if it is a time, is it a timestamp, a time of day, or a duration? (These are three very different things.)
admin an administrator, an administrative assistant, or a system administrator?
In context, you can usually figure these things out, but you have to think about them. That’s inefficient. Far better to just spell out what you mean from the get go.
There are a few abbreviations that are so well known and understood that they’re acceptable:
exfor an exception in a
catchclause (but nowhere else).
numfor number, though only when used as prefix as in
You can use single letter variable names for the occasional quantity that has no meaning other than its type. For example, a string variable can be named
s, an int variable
i, or a double variable
x. However, this should only be used when the program really doesn’t know anything about the nature of the variable other than its type. For example, a method that calculates the cube root of a double may name its argument
x; but a method that converts temperature from degrees Fahrenheit to degrees Celsius should name its argument
degreesFahrenheit, or perhaps
In addition, there’s nothing at all wrong with using common acronyms that are more recognized than what they stand for: URL, HTML, XML, XSL, etc. However, these are the exceptions, not the rules; and I would still be careful with common abbreviations that mean something else at first glance. EmployeeBO is almost certainly a Business Object, but that wasn’t what you read it as first, was it?
Code should be optimized for reading and comprehension, not for marginally faster typing. You should no more abbreviate names in your code than you do words in your sentences. No1 wnts 2 rd txt wrttn lk ths.