Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Underscore prefix on member variables. intellisense [duplicate]

everyone said the "underscore, no underscore" debate is purely philosophical and user preference driven but with intelli-sense having the underscore allows you to differentiate your member variables from your local variable very easily and thus giving you a concrete benefit

is there any counter argument to this benefit of having underscores to all member variables?

like image 582
leora Avatar asked May 07 '09 10:05

leora


2 Answers

Yes - for some people it reduces readability. I believe different people read in different ways (some internally vocalise and others don't, for instance). For some people (myself included) underscores interrupt the "flow" of code when I'm reading it.

I'd argue that if you're having difficulties telling local and instance variables apart, then quite possibly either your methods are too big or your class is doing too much. That's not always going to be the case of course, but I don't tend to find it a problem at all with short classes/methods.

like image 94
Jon Skeet Avatar answered Nov 15 '22 08:11

Jon Skeet


If it's just the intellisense you want you can always get it by typing "this.".

OK, it's 4 more chars than "_", but the intellisense will then bring up your members for you.

If you use underscores and your team uses underscores then keep using them. Others will use "m_", others might have other ideas. I use StyleCop and on my team the debate is over, we use "this." and Hungarian style or underscore prefixes are not used. And we just don't worry about it anymore.

[Edit] This is not a criticism of your question - it's a valid question and it's worth asking - but this debate wastes way too much time on dev projects. Even though I don't like everying about StyleCop I willingly use it as it cuts out this type of debate. Seriously, I've been in hour long meetings where this kind of discussion occupies a whole dev team. Crazy. Like I say, your question is valid but please don't waste your own time agonising over this, it's not worth it:-)

like image 22
Steve Avatar answered Nov 15 '22 09:11

Steve