Share this topic:

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!). 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... If words in the system you are working on 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 a regular words in the daily work) exist in any project, so, of course, they should be used to name objects.

2. Abbreviations, used as conventional terms by developers community working with a particular programming language or a particular area. 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. Long words or word-combinations used in a name of a LOCAL variable appearing in the function many times. In this case you have to add an explanatory comment to the variable's declaration line, for example:

Code: Select all
string pcm; // pcm = previous calculation method.

4. Words from the following list:

amt - amount
arg - argument
arr - array
asc - ascending
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!)
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
rc - return code
sel - select
src - source
srv - service
sum - summary
sys - system
temp - temporary
upd - update
val - value
win - window
User avatar
Site Admin
Posts: 111
Joined: 19 Feb 2013, 20:33

Return to Art of Naming

Who is online

Users browsing this forum: No registered users and 1 guest


Share this topic:

If you think that this site is not too bad, please LIKE it in Facebook. Thanks!

free counters

eXTReMe Tracker