473,750 Members | 2,213 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 "_MyVariabl e", wat benefit I am going to
achieve than just using "MyVariable ".

Thanks in advance.
Nov 15 '05 #1
10 8009
Vinod I wrote:
i.e., if I use a variable as "_MyVariabl e", 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.co m> wrote in message
news:eo******** ******@TK2MSFTN GP12.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 "_MyVariabl e", 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.co m> wrote in message
news:eo******** ******@TK2MSFTN GP12.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 "_MyVariabl e", 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.co m> wrote in message
news:eo******** ******@TK2MSFTN GP12.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 "_MyVariabl e", wat benefit I am going to
achieve than just using "MyVariable ".

Thanks in advance.

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

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

"Vinod I" <Vi****@PMAM.co m> wrote in message
news:eo******** ******@TK2MSFTN GP12.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 "_MyVariabl e", 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*********@al ternex.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.co m>
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.co m> wrote in message
news:eo******** ******@TK2MSFTN GP12.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 "_MyVariabl e", 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*********@al ternex.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*********@gm x.net> wrote in message
news:#U******** ******@TK2MSFTN GP12.phx.gbl...
Jon Skeet [C# MVP] wrote:
Phil C <ph*********@al ternex.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

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

Similar topics

43
5124
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 relative NOT to the immediate script that is including it, but is relative to the top-level calling script. In practice, this means that you have to constantly worry and adjust paths in includes, based on the startup scripts that call these...
2
2939
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 driven. The regex would include if/then/else type logic, and would like my script to conditionally execute the logic. -- http://www.dbForumz.com/ This article was posted by author's request
37
3979
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 a function
8
3617
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 <br>mais pour avoir des resultats probant il faut pas faire les mariolles, comme le &quot;fondateur&quot; de bvs
2
4004
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 arrow and you see the entries in a dropdown. But how would I control this thing from javascript? Here is the HTML: <div class="selection" style="top:0; left:89; width:159; height:21;"
5
3686
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
2845
by: manchin2 | last post by:
Hi, Can anybody please provide the information about "&quot" and its use, if possible please provide an example. 1)<tm:bom-expression>{Conf.getEquityConfLookupFields().getEventFieldText(&quot;AdditionalDisruption&quot;,&quot;Change in Law&quot;)}</tm:bom-expression> 2)07:41:08 Default ( call ( . ( call ( . Conf getEquityConfLookupFields ) ) getEventFieldText ) ( , AdditionalDisruption Change inLaw ) ) value=Not applicable Can you please...
4
4214
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": onclick="toggleDisplay(&lt;%#Eval(&quot;description&quot;)%>);">Administrator Functions</td> When putting <%#Eval('description')%> in <td> tag, it understand & show the correct value, but when in onclick='toggleDisplay(<%#Eval("description")%>);'> it didn't...
2
37791
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? Thanks, jmash
0
9000
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9577
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9339
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8260
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6804
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4887
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3322
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2804
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2225
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.