Subject: Common Abbreviations in Variable Names

From: Shlomi Fish <[email-masked]>
Date: Tue, 18 Sep 2001 20:22:27 +0300 (EEST)

Most of you realize that giving meaningful names to variables is a good
programming practice. On the other hand, most people don't like typing too
many characters, even if there is an auto-completion feature.

What many programmers do is use abbreviations for common names. Like "num"
for "number" or "iter(s)" for iteration(s). Does anybody know of a
collection of such abbreviations? I googlized for it but could not find
anything relevant. If all else fails, we (or should I say I) can start our
own.

Here are some from the top of my head:

a, b - common names for iterators and temporary variables
cmd - command
i, j - common names for iterators and temporary variables that hold
       integers.
iter - iteration (also: iters == iterations
num - number
obj - object
prod - product
ptr - pointer
ref - reference
str - string
var - variable
x, y, z - the x-y-z dimensions as well as iterators and temporary
variables

And so on.

Of course, there are many speicialized field in computer science which
have their own conventions. For instance, when working in Matlab, the
convulotion (what is which you don't want to know) is called conv. I used
to have variable names like "filters_in_fourier_domain" because I didn't
know how to abbreviate it.

Regards,

	Shlomi Fish

----------------------------------------------------------------------
Shlomi Fish        [email-masked]
Home Page:         http://t2.technion.ac.il/~shlomif/
Home E-mail:       [email-masked]

A more experienced programmer does not make less bugs. He just realizes
what went wrong more quickly.

---

From: mulix <[email-masked]>
Date: Wed, 19 Sep 2001 00:02:38 +0300 (IDT)

> a, b - common names for iterators and temporary variables

really? never seen those.

> i, j - common names for iterators and temporary variables that hold

istr something about the i coming from fortran, where the first letter
(only letter?) of the variable stood for its type. any of the old timers
care to enlighten us?

> iter - iteration (also: iters == iterations

also 'it'.

> str - string

you forgot the great catch all variable, 'tmp'.

> convulotion (what is which you don't want to know) is called conv. I used

err, i think that convulted parantesized clause was a great
demonstration of a convulation

> know how to abbreviate it.

sometimes, giving long meaningfull names to variables is sufficient
documentation. this is especially true when naming functions. sometimes,
giving meaningful names to variables is a hinderance.

i'll let you decide for yourself if using meaningful names in this
snippet i wrote for the r2l project was a good idea.

[note: this code sucks. dont bother flaming, i know].

static void
delete_argv_members(char* argv[], unsigned int how_many_left, unsigned
int how_many_to_delete)
{
     char** start = argv + how_many_to_delete;
     unsigned int index = 0;
     how_many_left -= how_many_to_delete;

     if (how_many_to_delete == 0)
          return;

     while (index < how_many_left){
          argv[index] = start[index];
          ++index;
     }

     for ( ; how_many_to_delete > 0 ; --how_many_to_delete)
          argv[index++] = NULL;
}

-- 
mulix

http://www.advogato.com/person/mulix
http://www.sf.net/projects/syscalltrack

---

From: "Nadav Har'El" <[email-masked]>
Date: Wed, 19 Sep 2001 00:30:53 +0300

> anything relevant. If all else fails, we (or should I say I) can start our

Most abbreviations are personal, i.e., someone likes to call a number "num",
and someone else likes to call it "n". I doubt you'll get very far with
making a list of such abbrevations.

Some abbreviations got popularized, however, by books, manual pages, and
the like. For example, it is common to see
	int fd; /* file descriptor */
	FILE *fp; /* file pointer */

more modern manuals usually name a file descriptor "fildes", not "fd",
and a file pointer "stream", not "fp" - I'm not sure why, or where they got
this convention (this is the convention both Solaris and Linux seem to
follow in the manpages).

Other names I often see is "s" for string (and s1, s2, etc. for other
strings), i, j, and k, for loop indices (obviously this use stems not
only from fortran, but more importantly from the original FORmulae that
fortran TRANslated, in which i,j,k are typically used as indices).
c is typically used for character, though it is frequently declared 
as int (see getchar(3) if you don't know why).

P.S. about your question about Fortran: If I remember correctly, Fortran 77,
by default, had any variable with its first letter [I-N] be an integer
and any other variable a "real" (floating-point). You could overide this
for a specific variable by declaring it, such as
	INTEGER*4 GOD
(one of my random sigs say "In fortran, God is real unless declared an
integer" ;) ), or by changing the implicit declaration default, using the
IMPLICIT command. The command
	IMPLICIT NONE
cancled the implicit definitions, and forced you to declare every variable.
But most people just stuck to the defaults, and chose the variable name
accordingly: so for example, if you need a variable to hold a row number
in a matrix, you would usually call it "IROW", so it would come out as an
integer ("ROW" would be real by default).

-- 
Nadav Har'El                        |    Wednesday, Sep 19 2001, 2 Tishri 5762
[email-masked]             |-----------------------------------------
Phone: +972-53-245868, ICQ 13349191 |Does replacing myself with a shell-script
http://nadav.harel.org.il           |make me impressive or insignificant?

---

From: Adi Stav <[email-masked]>
Date: Wed, 19 Sep 2001 01:12:46 +0300

On Tue, Sep 18, 2001 at 08:22:27PM +0300, Shlomi Fish wrote:
[snip]
> iter - iteration (also: iters == iterations

I use num for remembering sizes of arrays, i.e., 

struct bar {
	struct foo *foos;
	int num_foos;
}

> obj - object

This should probably never be used. I cannot think of any reasonable
circumenstances except for when writing your own object system where 
this name can convey any meaning.

> ptr - pointer

I personally use p for pointer

> var - variable

Ditto obj.

> x, y, z - the x-y-z dimensions as well as iterators and temporary

h for handler. Arguably ditto obj.

> really? never seen those.

*COUGH*sort*COUGH*COUGH*perl*COUGH*COUGH*braindamage*COUGH*

I also think a and b were used in K&R's original max()/min() 
functions. If not, then they're certainly used in many 
implementations of them.

[snip]
> demonstration of a convulation

Whatcha gonna do. Prepositions are never correct words to end 
sentences with. Talk about learning how to think in unorthodox
ways trying to get over a language's limitations :)

---

From: Adi Stav <[email-masked]>
Date: Wed, 19 Sep 2001 01:28:49 +0300

> giving meaningful names to variables is a hinderance.

My opinion (which admittedly has no Hungarian roots whatsoever) is
that a name should complement the type in conveying information.
Therefore the only reason to call a pointer "p" or "ptr" is if the
fact that is it a pointer IS its role in the function, as opposed
to, say, pointing to some specific object.

I think a name should always be meaningful to some degree. HOW
meaningful is a delicate decision. But no name should simply
repeat information that can be otherwise received from its 
delcaration in place of new and more important information.
On many occasions "tmp" is so much more meaningful than
"storage_of_pointer_to_foo_struct".

> [note: this code sucks. dont bother flaming, i know].

You're using 5-character indentation. May I ask what exactly is 
your hidden political agenda with this? :)

>      for ( ; how_many_to_delete > 0 ; --how_many_to_delete)

how_many_to_delete and how_many_left are good names IMO once you
strike out "how_many". Not because they're too long, but because 
"how_many" simply repeats information from the type.  "argv" is 
obviously a good name, though, because of the immediate association 
to main().

---

From: Shlomi Fish <[email-masked]>
Date: Wed, 19 Sep 2001 09:44:47 +0300 (EEST)

Incidently, once when I was converting a program from C to Java (MikMod) I
encountered a variable named "done". I believed it was a boolean value,
but it turned out it was an integer.

The program still run with the variable declared as bool, but it ran much
faster, once I modified it back to an integer. So, it should have been
named num_done, or something like that.

Regards,

	Shlomi Fish

---

From: Adi Stav <[email-masked]>
Date: Wed, 19 Sep 2001 12:46:32 +0300

> named num_done, or something like that.

This road leads to Hungary. You'd have to encode whether every C int 
is an integer or a boolean. Wouldn't it better to write what is being 
counted instead, e.g. bytes_done?

---

From: Shlomi Fish <[email-masked]>
Date: Wed, 19 Sep 2001 14:03:50 +0300 (EEST)

> demonstration of a convulation

Actually, that is not the Mathematical definition of convolution (sorry
for my own typo). In Mathematics a convolution is a process that takes two
functions (let's say from R -> R) and create a convolved function by means
of sampling the integral of the functions' multiplication when offseted by
a new variable. Notice that in the multiplication one of the functions
is reversed. (I told you you don't want to know what it is)

Convultion has many uses. For instance, it can be used to get the output
of a given signal from a Linear Time-Invariant (LTI) system. In a similar
manner it can be used to find a comulative system of two cascaded system.

Linearily and Time-Invariantly yours,

	Shlomi Fish

---

From: Shlomi Fish <[email-masked]>
Date: Wed, 19 Sep 2001 14:05:41 +0300 (EEST)

> counted instead, e.g. bytes_done?

Let's settle for num_bytes_done... ;-)

So we can have is_it_done vs. num_done with is_bytes_done and
num_bytes_done for clarity.

Regards,

	Shlomi Fish

>
> To unsubscribe from this group, send an email to:
> [email-masked]
>
>
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>
>

---

From: mulix <[email-masked]>
Date: Wed, 19 Sep 2001 17:03:51 +0300 (IDT)

> this name can convey any meaning.

i beg to disagree. obj should be used exactly in the same place that 'i'
or 'it' is used - where it is obvious what kind of object you're talking
about from the context, and anything more verbose is overkill.

then again, i grepped through my source and couldn't find a single place
where i've actually used the token 'obj', except in comments, so take
the above with a grain of salt.

> functions. If not, then they're certainly used in many

this reminds me of another pair of common tokens, 'lhs' and 'rhs'.
-- 
mulix

---

From: guy keren <[email-masked]>
Date: Wed, 19 Sep 2001 19:31:25 +0300 (EET DST)

> > > obj - object

[adi responded]
> > this name can convey any meaning.

actually any program that uses containers, manages objects. object
oriented code is exactly about writing your own objet system, even if the
root object isn't named 'Object'.

[muli responded]
> the above with a grain of salt.

actualy, i grepped some of my code, and i used 'obj' in several such
cases. most notably, sometimes when iterating (using 'iter') over a set of
objects, i used 'obj' to store the current iterated object, in order to
perform operations on it.

--
guy

"For world domination - press 1,
 or dial 0, and please hold, for the creator." -- nob o. dy

---

From: "Nadav Har'El" <[email-masked]>
Date: Wed, 19 Sep 2001 21:11:16 +0300

> is reversed. (I told you you don't want to know what it is)

With such a convoluted explaination (pun intented), no wonder convolutions
sounds complicated... (just kidding!)

They actually aren't that complicated, if you look at why they were invented,
and their original use - as a way to smooth functions. Take one arbitrary
function f, and a "smoothing function" g, the latter is a function with
integral of 1, say a narrow gaussian.

You want to "smooth" f using this gaussian g, by replacing the function value
at each point x by the weighed average of the function f at that point x
(weighed according to the given gaussian function g). This is the convolution
[of the original f and the gaussian g at the given x].

This turns out to be the same as doing an integral of the original function
times the moved second function (gaussian in my example) and taking the value
at the given point. I have to admit I don't remember why the second function
is flipped around x=0 (it doesn't matter anyway if the second function is
symmetric around x=0, as it was in the above gaussian example). 

It's all very much easier to understand if you draw a few simple pictures.

Of course, this isn't really a math list, so I won't get into exact
definitions, uses, or (my favorites) - "distributions" (just to give you
a taste: these are entities more general than functions that interact via
convolutions. The Dirac "delta" function Physicists so adore is actually a
distribution, not a function. Its convultion with a function f(x) results
in f(0)).

-- 
Nadav Har'El                        |    Wednesday, Sep 19 2001, 3 Tishri 5762
[email-masked]             |-----------------------------------------
Phone: +972-53-245868, ICQ 13349191 |The space between my ears was
http://nadav.harel.org.il           |intentionally left blank.

---

From: Adi Stav <[email-masked]>
Date: Thu, 20 Sep 2001 10:07:34 +0300

> perform operations on it.

Yes, that is true. Thank you.

---

From: Shlomi Fish <[email-masked]>
Date: Thu, 20 Sep 2001 12:46:15 +0300 (EEST)

> integral of 1, say a narrow gaussian.

The problem is that it is possible to convolve a function with another
function that will sharpen it.

> distribution, not a function. Its convultion with a function f(x) results

Actually a convolution of two functions is always another function. In our
case f(x) convolution delta(x) is equal to f(x).

Regards,

	Shlomi Fish

---

From: "Nadav Har'El" <[email-masked]>
Date: Thu, 20 Sep 2001 12:56:47 +0300

> function that will sharpen it.

Of course - I was just giving a way to think about what a convolution does.
People who never heard of convolutions have no idea what it is good for,
but most people can imagine why you'd want to smooth a function, and how
you'd do it.
After it is defined, it is used for more complex things.

> case f(x) convolution delta(x) is equal to f(x).

You're right. My stupid mistake. The value of the convolution at 0 is f(0),
but the convolution itself is indeed f(x), a function.

> > http://nadav.harel.org.il           |intentionally left blank.

This was an appropriate signature this time ;)

-- 
Nadav Har'El                        |     Thursday, Sep 20 2001, 3 Tishri 5762
[email-masked]             |-----------------------------------------
Phone: +972-53-245868, ICQ 13349191 |Willpower: The ability to eat only one
http://nadav.harel.org.il           |salted peanut.

---

From: Oleg Goldshmidt <[email-masked]>
Date: 20 Sep 2001 13:51:35 +0300

> (only letter?) of the variable stood for its type. any of the old timers

In the old Fortrans (the default is carried over to the newer ones,
for compatibility) variables starting with i,j,k,l,m,n were integers,
the rest - floats, unless explicitly declared. If you program Fortran,
I strongly suggest explicitly declaring all variables and not relying
on the defaults.

> you forgot the great catch all variable, 'tmp'.

Also src, dst, err, addr, incr, decr, del, rem, cpy, etc [this last
one deserves a smiley]. There is any number of these "generally
understandable" algorithms. Note btw [:-)] that some, such as ptr, are
better off in comments than in code.

-- 
Oleg Goldshmidt | [email-masked] 
"If it ain't broken, it has not got enough features yet."