Click to See Complete Forum and Search --> : Why we use m_, l_ etc?


The Saint
April 19th, 2005, 03:15 AM
Hi all,
The other day I had a dicussion with my friend on why we use such notations as m_, l_, g_ and how can the user know whether the particular variable is public/protected/private.
I thought that I can share this with you all and also know the other views or reasons. So here it goes.

The variables are prefixed by the following;
m_ for member variables
l_ for local variables
g_ for global variables
x_s for static variables and so on.

This was quite straight forward. The other issue was how would the user (programmer) know about the access of a variable.
Well, one thing is that almost all IDE's follow UML notations. So they use the UML notations for public/protected/private to denote the access. Moreover there are numerous plugins similar to the Intellisense of Visual Studio which display these notations thus making it possible for a programmer to know the access. Moreover the normal suggestion is to always declare public, protected and private in that order so that the user will be able to locate the variable/methods in that order.

In most cases, the header file is always released to the user and this order would help the user know the access.

Please pool in with your valuble thoughts.

ovidiucucu
April 19th, 2005, 03:25 AM
WARNING: this thread may have an infinite loop. :D

Different naming conventions are already much, much discussed here.
You want my opinion?
I do not agree "l_ for local variables". Am I doing something wrong?

The Saint
April 19th, 2005, 03:33 AM
Hmmmm... well just speaking from my personal experience i have come across l_, w_ or even just a _ and the beginning or end of the variable. So I am not taking sides. May be I will just sit and enjoy the ride. :)

cilu
April 19th, 2005, 03:34 AM
Did you forget about this thread of yours?

The Saint
April 19th, 2005, 03:41 AM
No. I do remember that very well . But I guess most of us not looking at the other point which is what I am more curious about. :confused:
How can the user know whether the particular variable is public/protected/private.

As a matter of fact these 2 questions were put up to me by a friend and I have just posted what I discussed with him :blush:

ovidiucucu
April 19th, 2005, 04:03 AM
How can the user know whether the particular variable is public/protected/private.
Prepend with pub/pro/priv :D

BTW. "The user" doesn't care about variables. He just use your program. ;)

cilu
April 19th, 2005, 04:20 AM
This was quite straight forward. The other issue was how would the user (programmer) know about the access of a variable.
Well, one thing is that almost all IDE's follow UML notations. So they use the UML notations for public/protected/private to denote the access. Moreover there are numerous plugins similar to the Intellisense of Visual Studio which display these notations thus making it possible for a programmer to know the access. Moreover the normal suggestion is to always declare public, protected and private in that order so that the user will be able to locate the variable/methods in that order.

In most cases, the header file is always released to the user and this order would help the user know the access.
What user? Do you mean the client that uses your class library? Well, with IntelliSense the problem is solved. All serious development environments today supports it.

On the other hand it isn't a good idea to use letter to indicate that a variable is private/protected/public. What if you want to change the access type? If you use that variable in 100 places than you have to make some more changes. ;)

Actually, you should not use public member data at all. They should all be private (perhaps protected) and provide accessors to them (Get/Set methods).

Sahir
April 19th, 2005, 04:42 AM
Prepend with pub/pro/priv :D

A dangerous trend. Can lead to unsavoury variable names :eek:

ovidiucucu
April 19th, 2005, 04:53 AM
A dangerous trend. Can lead to unsavoury variable names :eek:
This is what my smiley tries to say. ;)

Andreas Masur
April 19th, 2005, 05:03 AM
[ Moved thread ]

Andreas Masur
April 19th, 2005, 05:06 AM
...and how can the user know whether the particular variable is public/protected/private.
Well...I would say...by looking at the class declaration... :D