You are not logged in.
Pages: 1
Hello All,
I've been trying to find the best way to name variables, classes, forms, controls, etc... In our .NET projects. However, it seems like there are a lot of controversy when it comes to naming, and so I'd like to see what you guys think.
To start off, I have the following questions:
1 - Do you prefix your controls with their type abbreviation? Or do you Suffix them with their type name? Or do you suffix them with a simple 'Label / Field' ? (EX: txtFirstName , FirstNameTextBox, FirstNameField)
2 - When adding a new form, do you prefix the name, suffix the name, or leave it as it? (EX: frmLogin, LoginForm, Login)
3 - When you instantiate a private object from a Class, do you prefix it? If yes, what with? oProgram, cProgram, mProgram, _Program?
4 - Do you use the prefix 'm' for local private variables, and 'g' for public global variables?
Thanks :)
Last edited by Badieh (February 10 2015)
Camel Case FTW!
One approach would be to find a popular style guide and stick with it.
Examples:
- Microsoft style guide for C#
- Google style guide for C++
- Airbnb style guide for JavaScript
Thanks, however, these guidelines do not answer my questions. I've seen them before, and this is why i asked these questions specifically :).
Back when I was developing for .NET, we used StyleCop to deal with style guidelines. When all the rules are left checked, it can be very annoying to deal with, but it's all for the better. You get used to a strict style of writing code and it becomes muscle memory.
What you're asking about break the following two rules, so my answer to you is NO:
SA1305: FieldNamesMustNotUseHungarianNotation
SA1308: VariableNamesMustNotBePrefixed
Good luck.
Thanks xterm for your input, I've read so many posts hating on hungarian notations. Kind of easy to avoid for variables, but kind of sucks for Controls. How would you name your controls? TextBoxUserName? UserNameTextBox? UserNameField?
To start off, I have the following questions:
1 - Do you prefix your controls with their type abbreviation? Or do you Suffix them with their type name? Or do you suffix them with a simple 'Label / Field' ? (EX: txtFirstName , FirstNameTextBox, FirstNameField)
2 - When adding a new form, do you prefix the name, suffix the name, or leave it as it? (EX: frmLogin, LoginForm, Login)
3 - When you instantiate a private object from a Class, do you prefix it? If yes, what with? oProgram, cProgram, mProgram, _Program?
4 - Do you use the prefix 'm' for local private variables, and 'g' for public global variables?
Hey,
there's no general rule for what you are asking, but there's a best practice,
1- For that its better to stick to one convention for all the controls, FirstName_TextBox for example, here the name is divided into the DescriptionOfTheField_DescriptionOfTheControl.
2- LoginForm or Login_Form, leaving a Form name without prefix/suffix will make you suffer when the project get bigger or when you come after a while to check something in it.
3- For private object name, lower first character case is enough : program.
4- For private variables add "_" , _transactionDate , public variables: TransactionDate.
Badieh wrote:To start off, I have the following questions:
1 - Do you prefix your controls with their type abbreviation? Or do you Suffix them with their type name? Or do you suffix them with a simple 'Label / Field' ? (EX: txtFirstName , FirstNameTextBox, FirstNameField)
2 - When adding a new form, do you prefix the name, suffix the name, or leave it as it? (EX: frmLogin, LoginForm, Login)
3 - When you instantiate a private object from a Class, do you prefix it? If yes, what with? oProgram, cProgram, mProgram, _Program?
4 - Do you use the prefix 'm' for local private variables, and 'g' for public global variables?Hey,
there's no general rule for what you are asking, but there's a best practice,1- For that its better to stick to one convention for all the controls, FirstName_TextBox for example, here the name is divided into the DescriptionOfTheField_DescriptionOfTheControl.
2- LoginForm or Login_Form, leaving a Form name without prefix/suffix will make you suffer when the project get bigger or when you come after a while to check something in it.
3- For private object name, lower first character case is enough : program.
4- For private variables add "_" , _transactionDate , public variables: TransactionDate.
Thanks, this is what I went with in the end, except without the underscores since some hate on it. As for private vs Global members, I am prefixing them with 'm' and 'G'. I wanted to go with the underscore, but again, many hate on that.
Pages: 1