Tutorial :mSomeVar names - where from and why?



Question:

Variables in Android sources are prefixed with m, like mStream or mHeaderValueIndex. What's the rationale behind Hungarian notation here?


Solution:1

The "m" is short for member. It's just a way of letting you know you're dealing with a class member variable. In other environments or programming languages, you might use an underscore prefix instead.


Solution:2

The rationale for putting prefixes like "m" or "m_" or "_" on attribute names is to make them easier to distinguish from local variables and parameters.

But all IDEs (and a lot of text editors) are capable of using different colours to render attribute names and local or parameter names, which makes this convention is pretty much a waste of time these days. And you will notice that the Sun Java Style Guide does not "bless" this convention.

But who knows why they chose to do this in the Android codebase. Perhaps they were trying to align their Java, C and C++ coding standards? Perhaps Google coders all use black-and-white monitors? :-)


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »