wyrd Posted April 5, 2003 Posted April 5, 2003 I've been looking to perhaps change my style in programming just a tad. However, I can't remember which language an underscore at the beginning of a variable was considered bad (ie; _somevar). Was it C++, Java or .NET? I can't remember. :( In any case, I've been thinking about using _somevar rather then say, somevar (which I usually use, heh). So, my code would look something like this.. public class Hi { private string _s; private int _i; public Hi(string s, int i) { _s = s; _i = i; } } I know back in the days (heh, wasn't that long ago I suppose), it was something like m_somevar, however being anal as I am, I hate the extra typing (yeah, I know, it's just one char for crying out loud), and not to mention I just hate the way the m_ looks, and in my opinion just a single _ sticks out more. Anyway.. suggestions, thoughts, inputs? And if anyone knows which language the _ is considered bad in please tell me, it's going to bother me until I remember, heh. Quote Gamer extraordinaire. Programmer wannabe.
solus Posted April 5, 2003 Posted April 5, 2003 Well, in c++ a variable must begin with a letter, so an underscore is out of the question. I have no idea about Java and I was really suprised you could head a variable with an underscore in c#. In any case, whatever works for you. It's your code. Quote Can't afford to be neutral on a moving train...
Moderators Robby Posted April 5, 2003 Moderators Posted April 5, 2003 Funny thing is I find that m_var sticks out more than _var, that being said, I started using the former. To be honest, I'm not sure that I'm comfortable with it. btw, I do the same in C# as in VB. Quote Visit...Bassic Software
*Experts* Volte Posted April 5, 2003 *Experts* Posted April 5, 2003 I always use _memberVariable; as much as I dislike using underscores in variables, it works. Quote
*Experts* jfackler Posted April 5, 2003 *Experts* Posted April 5, 2003 Wyrd, I've been doing my best to learn this language using all of you as my tutors and reading all the resources I can get my hands on. As such I've read a lot of the old posts on this forum. Trying to catch up. Stumbled across this one from last December. Thought you might get a kick out of it. http://www.xtremedotnettalk.com/showthread.php?s=&threadid=49529&highlight=thumbnail Quote
wyrd Posted April 5, 2003 Author Posted April 5, 2003 jfackler: Yeah I remember that post. I still hate strVariable and m_variable. :p Quote Gamer extraordinaire. Programmer wannabe.
Leaders Squirm Posted April 5, 2003 Leaders Posted April 5, 2003 I just use m and not bother with an underscore. Quote Search the forums | Still IRCing | Be nice
*Gurus* divil Posted April 5, 2003 *Gurus* Posted April 5, 2003 I often (when using C#) differentiate between private member variables and the public properties that reflect them by the casing of the first letter. I'll use camel case for the private member variable. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
*Experts* Nerseus Posted April 7, 2003 *Experts* Posted April 7, 2003 I do the same as divil. So: private string firstName; private string lastName; private int age; public string FirstName { get { return this.firstName; } } public string LastName { get { return this.lastName; } } public string Age { get { return this.age; } } This won't work in VB since it's case-insensitive (can't have a private firstName and a public FirstName). We also dropped all hungarian notation as the variable name is good enough about 90% of the time and the other 10% can be figured out at a glance. I despise the leading underscore, though I think it was relatively valid in C (not C++ or any other language for that matter). They even use two underscores for some reason though I could *never* quite see which vars had one and which had two underscores in the old IDEs. I worked with a guy many years ago in VB3 who used 1, 2 and 3 underscores at the end of variables to designate scope: 1 for a function, 2 for a form level and 3 for global (remember the keyword Global? :)). He eventually commited suicide. I wouldn't worry a WHOLE lot, wyrd, as long as you're consistent. Chances are that when you go to work somewhere, they'll already have a naming convention and you'll have to follow it. Or, in some cases, a client will dictate naming conventions (such as on a database, if they use a brand/version different than the one you're used to). -Nerseus Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Heiko Posted April 7, 2003 Posted April 7, 2003 Be consistent. That's all I can say. Just for the record, in our project: mThis for class-wide private vars. pThis for vars that have been passed into the method as a parameter. this for all other vars. additionally, controls and database objects get the well known prefixes (tblThis, rowThat, lvwThis, txtThat). Quote .nerd
*Gurus* Derek Stone Posted April 8, 2003 *Gurus* Posted April 8, 2003 I think it is rather ironic that those developers who choose to use any form of notation on variables neglect to use that same notation on member variables. -This- makes little sense to me. Quote Posting Guidelines
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.