473,387 Members | 1,365 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

"m_" prefix in classes

I see m_ prefixed in front of variable names all the time in code for
classes. Is this a coding convention and if so how does one describe the
type of variables it is used with?

Thanks in advance.

May 18 '07 #1
8 6969
"Internet User" <no*****@noemail.comwrote in news:#ZffhMYmHHA.4960
@TK2MSFTNGP02.phx.gbl:
I see m_ prefixed in front of variable names all the time in code for
classes. Is this a coding convention and if so how does one describe the
type of variables it is used with?
m_ means member variable ... a class level variable.

just _ i.e. Dim _MyVariable as String is used for local variables.

But it's personal preference. Microsoft had a naming guide online, but from
what I recall it wasn't all that indepth.

May 18 '07 #2
"Internet User" <no*****@noemail.comschrieb:
>I see m_ prefixed in front of variable names all the time in code for
classes. Is this a coding convention and if so how does one describe the
type of variables it is used with?
'm_' is typically used to mark private variables in order to make their
scope more visible and to prevent name clashes with the class' public
properties. Imagine a class having a 'UserName' property. The property's
value could be stored in a private "backing field" named 'm_UserName', for
example.

To me the 'm' stands for "module-level" (module = module, structure, class)
opposed to 'g' which stands for "global" (and which I am using almost
never).

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

May 18 '07 #3
Thanks. Exactly what I needed.

"Herfried K. Wagner [MVP]" <hi***************@gmx.atwrote in message
news:ew**************@TK2MSFTNGP04.phx.gbl...
"Internet User" <no*****@noemail.comschrieb:
>>I see m_ prefixed in front of variable names all the time in code for
classes. Is this a coding convention and if so how does one describe the
type of variables it is used with?

'm_' is typically used to mark private variables in order to make their
scope more visible and to prevent name clashes with the class' public
properties. Imagine a class having a 'UserName' property. The property's
value could be stored in a private "backing field" named 'm_UserName', for
example.

To me the 'm' stands for "module-level" (module = module, structure,
class) opposed to 'g' which stands for "global" (and which I am using
almost never).

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

May 18 '07 #4
Thanks.

"Spam Catcher" <sp**********@rogers.comwrote in message
news:Xn**********************************@127.0.0. 1...
"Internet User" <no*****@noemail.comwrote in news:#ZffhMYmHHA.4960
@TK2MSFTNGP02.phx.gbl:
>I see m_ prefixed in front of variable names all the time in code for
classes. Is this a coding convention and if so how does one describe the
type of variables it is used with?

m_ means member variable ... a class level variable.

just _ i.e. Dim _MyVariable as String is used for local variables.

But it's personal preference. Microsoft had a naming guide online, but
from
what I recall it wasn't all that indepth.

May 18 '07 #5
It's an old VB coding convention meaning module. The scope is class-wide,
i.e., a Private variable.

"Internet User" <no*****@noemail.comwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
>I see m_ prefixed in front of variable names all the time in code for
classes. Is this a coding convention and if so how does one describe the
type of variables it is used with?

Thanks in advance.

May 18 '07 #6
Spam catcher had it right... At least according to what I read....
"Internet User" <no*****@noemail.comwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
>I see m_ prefixed in front of variable names all the time in code for
classes. Is this a coding convention and if so how does one describe the
type of variables it is used with?

Thanks in advance.
May 19 '07 #7
"Earl" <br******@newsgroups.nospamschrieb:
It's an old VB coding convention meaning module. The scope is class-wide,
i.e., a Private variable.
IIRC the convention has been "borrowed" from C++, but it's hard to determine
the exact roots of it.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

May 19 '07 #8
Eh, I would've mentioned that, but actually I think Al Gore invented it.

"Herfried K. Wagner [MVP]" <hi***************@gmx.atwrote in message
news:eX**************@TK2MSFTNGP04.phx.gbl...
"Earl" <br******@newsgroups.nospamschrieb:
>It's an old VB coding convention meaning module. The scope is class-wide,
i.e., a Private variable.

IIRC the convention has been "borrowed" from C++, but it's hard to
determine the exact roots of it.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

May 19 '07 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: BJörn Lindqvist | last post by:
I think it would be cool if you could refer to instance variables without prefixing with "self." I know noone else thinks like me so Python will never be changed, but maybe you can already do it...
26
by: Fernando M. | last post by:
Hi, i was just wondering about the need to put "self" as the first parameter in every method a class has because, if it's always needed, why the obligation to write it? couldn't it be implicit?...
10
by: Vinod I | last post by:
Hi Team, I just want to know, wat is the relevance /or benefit of using "_" before a variable. i.e., if I use a variable as "_MyVariable", wat benefit I am going to achieve than just using...
4
by: Craig Kenisston | last post by:
I've notice that some Microsoft's code, uses the "m_" convention to refer t private member fields Check this http://support.microsoft.com/default.aspx?scid=kb;EN-US;32608...
6
by: Anders Borum | last post by:
Hello! I'm wondering what the recommendations are for using the "this" keyword? The problem is that I really like to use the "this" keyword, but it tends to make the code more verbose (which...
12
by: MuZZy | last post by:
Hi, Sorry for a repeated post but i didn't receive an answer and will try to re-phrase my question: How do i close an additional thread from the main thread, if this additional thread is stuck...
5
by: Agnes | last post by:
For my own practices. I like to put "Me". e.g IF Me.txtInvoice.textlength = 0 ....... etc Me.txt.....etc However, Is there any difference (without Me) ?? Thanks
60
by: Dave | last post by:
I'm never quite sure whether to use "this." or not when referring to fields or properties in the same class. It obviously works just fine without it but sometimes I wonder if using this....
14
by: Alexander Dong Back Kim | last post by:
Dear all, I used to use C++ programming language at all time but moved to C# and Java. Few days ago, I restarted studying about C++ with a very beginner's mind. I wrote a simple class and gcc...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.