Abbreviations in names

Link to this posting

Postby Ursego » 21 Feb 2013, 10:28

Shorten words in names ONLY if the produced abbreviation is more than obvious.

Trying to decrease our methods’ size, we usually shorten words while creating names of our tables, columns, application objects, scripts and variables. Sometimes we shorten them slightly, sometimes - significantly, it usually depends on a practice existing in your company. In one of my working places I was suffering from very strict rules of shortening; they shortened everything they saw! They didn’t use vowels except leading ones (wrk - work, crtfc - certificate, insr - insurance etc.) and had other official rules how to remove meat from bones (when I didn't understand one of such "wrds", I opened a special list of abbreviations! :o ). Those names were understandable only to ancient Egyptians, so I was happy when my contract had ended.

In another project, I saw the opposite picture: no shortening at all! OK, sometimes (easy stuff like "id", "sys", "col" or "num"), but usually - full sentences used as names of tables, fields, functions etc. I was reading scripts as if they would be an adventures book, not as programming language code! Initially, I was slightly in shock: how do they do that? Don’t they know that everybody must try to keep their scripts shorter? It was not according to what I had seen in different projects during multiple years of my career... But I want to tell you - it was real pleasure to work on this project! So, accept this shocking and unusual, but great idea: try NOT to shorten words in your objects' names! Of course, only guys who creates new systems (including DB objects) can utilize this advice, and only if the DBMS allows long names (unfortunately, the max identifier length in the Sybase database is 30, so you will become an ancient Egyptian :lol: ). If words in your system have already been mangled, you can do nothing with that - use names as they already exist, don't create versions of names for same entities (consistency is above all!).

Here I list exclusive 4 cases when abbreviations should appear in our code:

1. Abbreviations, used as conventional terms in the business. Such abbreviations (which have become regular words in the daily work) exist in any project, so, of course, they should be used in identifiers.

2. Abbreviations, used as conventional terms by developers community, working with the programming language or technology. For example, each PowerBuilder programmer knows that DS stands for "DataStore", each C/C++ writer knows that "ptr" stands for "pointer", and each database specialist knows the meaning of "PK" and "FK".

3. Abbreviations for long words or word-combinations, used in a name of a LOCAL variable which is mentioned in the function many times. In this case you have to add an explanatory comment to the variable's declaration line, like in the following example, taken from one of my projects:

Code: Select all
String ccm; // current calculation method
String pcm; // previous calculation method

4. Words from this list:

amt - amount
arg - argument
arr - array
asc - ascending
avg - average
buf - buffer
calc - calculate, calculation
col - column
cnt - count (not counter!)
ctr - counter
cust - customer
curr - current
def - definition
del - delete
desc - descendant (not description!)
descr (dscr) - description
dest - destination
dif - difference
doc - document
elig - eligible, eligibility
emp - employee (not employer!)
env - environment
err - error
exp - expired, expiration (not expression!)
expr - expression
frag - fragment
id - identifier
idx - index
img - image
ind - indicator (not index!)
ins - insert (not insurance!)
ini(t) - initial
info - information
ins - insert
inv - invoice (not inventory!)
qty - quantity
len - length
max - maximum
min - minimum
misc - miscellaneous
msg - message (not monosodium glutamate :lol: )
num - number
obj - object
orig - original
parm - parameter
pos - position
prev - previous
ptr - pointer
ref - reference
res - result
ret - return(ed)
rc - return code
sel - select
src - source
sum - summary
svc - service
sys - system
temp - temporary
upd - update
val - value
win - window
User avatar
Site Admin
Posts: 131
Joined: 19 Feb 2013, 20:33

IF you want to ((lose weight) OR (have unbelievable (brain function AND mental clarity))) THEN click:

free counters

eXTReMe Tracker