Answer the question
In order to leave comments, you need to log in
Do you use underscores to name global variables?
Today I had a discussion with a colleague.
In all the projects that I was involved in, I always set a rule - global variables begin with the _ symbol.
I.e
class A<br/>
{<br/>
...<br/>
int _variable;<br/>
...<br/>
}
Answer the question
In order to leave comments, you need to log in
Traditionally, the name of a private variable begins with an underscore, constants are typed in upper case (in all capital letters), and everything else is in small letters.
The absence of global variables allows you to understand the code even better.
when I use C#, if private/protected, then I start with a small letter, if the element is public, I start with a capital letter, without underlining.
I try to do as it is written in msdn guidline .
Each language has its own standards + as you like :)
Where did you find global variables in C#?
What you have is class fields, and yes, it is customary to write them with underlining.
No. For cases when you yourself are not sure what you are writing / your imagination has ended / some kind of conflict, there is this.
I don't like Python-style even in python itself.
I have global variables called long, distinct names, and local variables are short, often single-letter.
I understand from your example that you call the private fields of the class global. If so, then I name them as well.
Interestingly, as recently as this week, this issue was discussed at a rally. I was for underscores. My arguments:
globals (which is very rare) I name g_{name},
class methods in C++ - m_{name} or just _{name}, in php - class methods $_{name}
php - private/protected starts with "_" (standard), applies to both properties and methods.
the place where I do not agree with the MS convention. The this construct. I'm not happy at all. Maybe a habit. So I support underscore.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question