0

Possible Duplicate:
Why should (or shouldn't) I prefix fields with 'm_' in C#?

I am reading CLEAN CODE

there is one paragraph about member prefixed.

THe author suggests not using m_ anymore. such as:

public class Part{
  private String m_dsc;
  void setName(String name){
    m_dsc - name;
  }
}

should be:

public class Part{
  String description;
  void setDescription(String description){
    this.description = description'
  }
}

My question is, why we use m_ before?

And, this book is using Java as an example. Is this suggestion good for c# ? what about c++

Thank you!

Community
  • 1
  • 1
David Degea
  • 1,378
  • 2
  • 12
  • 18

2 Answers2

4

m_ is variant of Hungarian notation - http://en.wikipedia.org/wiki/Hungarian_notation.

Using it or not is personal/team call, but the recommendation to not to use prefixes for fields is a long standing one for C# - http://msdn.microsoft.com/en-us/library/ms229012.aspx .

Michelle
  • 663
  • 1
  • 8
  • 17
Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179
2

The m_ prefix makes it easy to differentiate member variables with local variables or parameters.

This is valid for classes in object oriented languages (so, yes C#, C++, etc.)

Now, with the advances in IDEs, the m_ prefix doesn't seem to be as useful though (in the case where you're wondering if a variable is a class member or not, it's easy and fast to go to definition.)

JeanHogue
  • 64
  • 1
  • 2
    In OOP languages like C# or Java there is absolutely no need to prefix it with `m_` or `_`. If you need to distinguish it as a member variable you should use the `this` keyword. – user1021726 Dec 17 '13 at 09:03