Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Variable names must not start with 'm_' : StyleCop Rule 1308 - Why is it considered a bad (or not good/standard) practice?

I have started using the StyleCop and it gives warning wherever there is a variable declared like m_VariableName.

The warning message is : Variable names must not start with 'm_'. This is StyleCop rule SA1308.

I can turn this rule off. But

1) I would like to know why is it a bad practice or considered to be a bad practice to declare variable names starting with 'm_'?

2) Does the underscore character has a special meaning for Visual Studio refactoring? (I heard it from one of the senior developers.)

like image 303
Learner Avatar asked Apr 20 '11 07:04

Learner


People also ask

What makes for a good or bad variable name?

The variable name must describe the information represented by the variable. A variable name should tell you concisely in words what the variable stands for. Your code will be read more times than it is written.

What are the rules for naming a variable in MATLAB?

A valid variable name starts with a letter, followed by letters, digits, or underscores. MATLAB® is case sensitive, so A and a are not the same variable. The maximum length of a variable name is the value that the namelengthmax command returns.

What is not allowed when naming variables?

Specifically, spaces are not permitted in the variable names, as variable name must be a single word. Variable name may not start with a digit or underscore, and may not end with an underscore. Double underscores are not permitted in variable name.


2 Answers

The default StyleCop rules follow the Microsoft C# coding style.

These include not using m_ as a prefix (seen as Hungarian Notation).

If your team does not follow these style guidelines and has your own, feel free to switch the rule off.

like image 75
Oded Avatar answered Sep 17 '22 23:09

Oded


It just matches Microsoft's naming guidelines for Fields:

Do not use a prefix for field names. For example, do not use g_ or s_ to distinguish static versus non-static fields.

I believe it was part of the general purge of Hungarian that Microsoft attempted to implement when they introduced .NET.

But as with all things around coding style, if it doesn't fit what you and/or your team are comfortable with, then don't use it.

like image 29
Damien_The_Unbeliever Avatar answered Sep 18 '22 23:09

Damien_The_Unbeliever