This post originated from an RSS feed registered with Java Buzz
by Elliotte Rusty Harold.
Original Post: Dn't Abbrvt
Feed Title: The Cafes
Feed URL: http://cafe.elharo.com/feed/atom/?
Feed Description: Longer than a blog; shorter than a book
Is res a response, a reservation, a resume, or a result?
Is def a default or a definition?
Is v1 version 1 or value 1?
Is e an event, an entity, or an exception?
Is f a file or a float?
Is lst a list or the least value?
Is temp a temporary variable or a temperature reading?
Is 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.)
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:
max for maximum
min for minimum
in for InputStream
out for OutputStream
e or ex for an exception in a catch clause (but nowhere else).
num for number, though only when used as prefix as in numTokens, or numHits.
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 degrees, degreesFahrenheit, or perhaps temperatureFahrenheit.
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.