Skip to main content
Drop all encouragements for "discussing" the question. Ask a clear question about the practical and cultural aspects.
Source Link

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

I've been a C++ programmer for almost 12 years now. When I moved to C# two years ago I brought with me the same coding style I was so accustomed to. Soon I realized how much useless it was in C# and gradually started to drop all of my old habits... but the 'm_' thing.

I've never been a fan of Hungarian notation, I've always found it pretty useless unless you're doing some really low level programming, but in every C++ project I've worked on some kind of Hungarian notation policy was enforced, and with it the use of some 'not-really-Hungarian' prefixes as m_ for fields, s_ for statics, g_ for globals and so on.

Now,Soon I realized how much useless it was in C# and gradually started to drop all of my old habits... but the 'm_' thing. I still use the m_ prefix on private fields because I really find it very useful to being able to distinguish between paramsparameters, locals and fields.

The naming conventions for fields page at MSDN says I shouldn't, but something in the back of my head says that I'm doing it the C++does not say why (the way e.g. Google's conventions generally tend to rationalize their prescriptions).

I'd love to hear your opinions soAre there reasons why I can finally decide whichshouldn't or is the 'best way'

Thanksit only a matter of style. If it is the latter, are prefixes generally considered a bad style and can I expect negative reactions from other people working on the codebase?

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

I've been a C++ programmer for almost 12 years now. When I moved to C# two years ago I brought with me the same coding style I was so accustomed to. Soon I realized how much useless it was in C# and gradually started to drop all of my old habits... but the 'm_' thing.

I've never been a fan of Hungarian notation, I've always found it pretty useless unless you're doing some really low level programming, but in every C++ project I've worked on some kind of Hungarian notation policy was enforced, and with it the use of some 'not-really-Hungarian' prefixes as m_ for fields, s_ for statics, g_ for globals and so on.

Now, I still use the m_ prefix on private fields because I really find it very useful to being able to distinguish between params, locals and fields, but something in the back of my head says that I'm doing it the C++ way.

I'd love to hear your opinions so I can finally decide which is the 'best way'

Thanks.

Why shouldn't I prefix my fields?

I've never been a fan of Hungarian notation, I've always found it pretty useless unless you're doing some really low level programming, but in every C++ project I've worked on some kind of Hungarian notation policy was enforced, and with it the use of some 'not-really-Hungarian' prefixes as m_ for fields, s_ for statics, g_ for globals and so on.

Soon I realized how much useless it was in C# and gradually started to drop all of my old habits... but the 'm_' thing. I still use the m_ prefix on private fields because I really find it very useful to being able to distinguish between parameters, locals and fields.

The naming conventions for fields page at MSDN says I shouldn't, but it does not say why (the way e.g. Google's conventions generally tend to rationalize their prescriptions).

Are there reasons why I shouldn't or is it only a matter of style. If it is the latter, are prefixes generally considered a bad style and can I expect negative reactions from other people working on the codebase?

Post Closed as "not constructive" by Adam Lear
edited tags
Link
Erik Funkenbusch
  • 93.7k
  • 29
  • 201
  • 292
Source Link
Trap
  • 12.4k
  • 15
  • 59
  • 69

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

I've been a C++ programmer for almost 12 years now. When I moved to C# two years ago I brought with me the same coding style I was so accustomed to. Soon I realized how much useless it was in C# and gradually started to drop all of my old habits... but the 'm_' thing.

I've never been a fan of Hungarian notation, I've always found it pretty useless unless you're doing some really low level programming, but in every C++ project I've worked on some kind of Hungarian notation policy was enforced, and with it the use of some 'not-really-Hungarian' prefixes as m_ for fields, s_ for statics, g_ for globals and so on.

Now, I still use the m_ prefix on private fields because I really find it very useful to being able to distinguish between params, locals and fields, but something in the back of my head says that I'm doing it the C++ way.

I'd love to hear your opinions so I can finally decide which is the 'best way'

Thanks.