473,387 Members | 1,859 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.

Relevance of "_"

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 "MyVariable".

Thanks in advance.
Nov 15 '05 #1
10 7980
Vinod I wrote:
i.e., if I use a variable as "_MyVariable", wat benefit I am going to
achieve than just using "MyVariable".


The only benefit to any naming convention is consistency which aids
readability.

--
There are 10 kinds of people. Those who understand binary and those who
don't.

http://code.acadx.com
(Pull the pin to reply)
Nov 15 '05 #2
Nothing. You can name variables however you like - no special treatment
from the compiler :)

-vJ

"Vinod I" <Vi****@PMAM.com> wrote in message
news:eo**************@TK2MSFTNGP12.phx.gbl...
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 "MyVariable".

Thanks in advance.

Nov 15 '05 #3
dear vinod.
we use "_ " mostly to differentiate properties from variables, we can use
_MyProp for proiperties and variable without _,and regarding benefit this is
naming convention and it can vary according to company standards u work for
.. u can check with your company naming conventions.
"Vinod I" <Vi****@PMAM.com> wrote in message
news:eo**************@TK2MSFTNGP12.phx.gbl...
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 "MyVariable".

Thanks in advance.

Nov 15 '05 #4
Thanks for the feedbacks.

There was a differentiation between these types of declarations in VB6/COM.

"Vinod I" <Vi****@PMAM.com> wrote in message
news:eo**************@TK2MSFTNGP12.phx.gbl...
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 "MyVariable".

Thanks in advance.

Nov 15 '05 #5
"Vinod I" <Vi****@PMAM.com> wrote in message news:<uR**************@tk2msftngp13.phx.gbl>...
Thanks for the feedbacks.

There was a differentiation between these types of declarations in VB6/COM.

"Vinod I" <Vi****@PMAM.com> wrote in message
news:eo**************@TK2MSFTNGP12.phx.gbl...
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 "MyVariable".

Thanks in advance.

A lot of people used to use m_variableName to name their member
variables. This was/is a great way to differentiate between the
class' member variables and temporary local variables.
Nowadays a lot of developers use _variableName for the same reasons as
above but the 'm' was dropped since it's redundant

This also makes the constructor more readable..
this.foo = foo
becomes
_foo = foo
Nov 15 '05 #6
Phil C <ph*********@alternex.net> wrote:
This also makes the constructor more readable..
this.foo = foo
becomes
_foo = foo


Well, that's certainly subjective - I prefer the first form, finding _
very distracting when it's all over the place.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #7
Basically this was like using "m_" in C++ for private variables. I use this
in the following way.

public class MyClass {
private string _myString;

public string MyString {
get { return this._myString; }
}

public MyClass (string s) {
this._myString = s;
}
}

I use it as a nice way to link my properties to the variables in the class
with out exposing the variable.

"Vinod I" <Vi****@PMAM.com> wrote in message
news:eo**************@TK2MSFTNGP12.phx.gbl...
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 "MyVariable".

Thanks in advance.

Nov 15 '05 #8
Jon Skeet [C# MVP] wrote:
Phil C <ph*********@alternex.net> wrote:
This also makes the constructor more readable..
this.foo = foo
becomes
_foo = foo


Well, that's certainly subjective - I prefer the first form, finding _
very distracting when it's all over the place.


Full ACK. If the language already has means to express "instance" access
(this.), why come up with weird coding conventions anyway. Plus, I hate
inconsistencies in code style between generated code and manually written
code.

Cheers,

--
Joerg Jooss
jo*********@gmx.net

Nov 15 '05 #9
Normally hidden fields are prefixed and if you need public exposure use
properties.

The problem with the this. notation while giving a clear indication that its
this instance you are referring to it polutes any mathmitical formulas you
may have with keyword spam.

Its easier to sit down with a numbers guy who formualted the formula and
step thru in the debugger with each value without having to explain what
"this" means.

These guys arnt programmers nor do they care.

"Joerg Jooss" <jo*********@gmx.net> wrote in message
news:#U**************@TK2MSFTNGP12.phx.gbl...
Jon Skeet [C# MVP] wrote:
Phil C <ph*********@alternex.net> wrote:
This also makes the constructor more readable..
this.foo = foo
becomes
_foo = foo


Well, that's certainly subjective - I prefer the first form, finding _
very distracting when it's all over the place.


Full ACK. If the language already has means to express "instance" access
(this.), why come up with weird coding conventions anyway. Plus, I hate
inconsistencies in code style between generated code and manually written
code.

Cheers,

--
Joerg Jooss
jo*********@gmx.net

Nov 15 '05 #10
<di********@discussion.microsoft.com> wrote:
Normally hidden fields are prefixed and if you need public exposure use
properties.
When you say "normally" - do you mean "in your code"? I rarely work
with code which uses prefixes...
The problem with the this. notation while giving a clear indication that its
this instance you are referring to it polutes any mathmitical formulas you
may have with keyword spam.


True - I only use it in the rare cases when I have parameters with the
same name. If you keep your methods short enough (which is a good idea
anyway) it's really not a problem, IMO.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #11

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

Similar topics

43
by: steve | last post by:
I am quite frustrated with php’s include, as I have spent a ton of time on it already... anyone can tell me why it was designed like this (or something I don’t get)? The path in include is...
2
by: steve | last post by:
Hi, I need to do conditional script "include", but like to pull the code from db instead of a file. How do I do that? Reason: I like to implement some complex regex logic, and make it table...
37
by: jht5945 | last post by:
For example I wrote a function: function Func() { // do something } we can call it like: var obj = new Func(); // call it as a constructor or var result = Func(); // call it as...
8
by: Ulysse | last post by:
Hello, I need to clean the string like this : string = """ bonne mentalit&eacute; mec!:) \n <br>bon pour info moi je suis un serial posteur arceleur dictateur ^^* \n ...
2
by: Angus | last post by:
I am trying to change the selection in Javascript - but this HTML element is not a standard option control. On the web page it looks like a dropdown list - and you click on the right hand down...
5
by: Maria Sudderman | last post by:
I have a prblem with the "onClick" command. onClick="insert('<a href="URI">', '</a>')"> but this is not correct! why? Maria
1
by: manchin2 | last post by:
Hi, Can anybody please provide the information about "&quot" and its use, if possible please provide an example. ...
4
by: thaytu888888 | last post by:
Here is my codes in aspx page: <td colspan="2" class="main_menu" runat="server" onclick='toggleDisplay(<%#Eval("description")%>);'><%#Eval("description")%></td> Here is in "View source": ...
2
by: jmash | last post by:
Suppose I have the following string whch is part of an xml string: String s= "Script Id=&quot;Test&quot; " And I need to get s= "Script Id="Test" " Can anyone tell me how this can acheived? ...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.