mSomeVar names - where from and why?

给你一囗甜甜゛ 提交于 2019-12-11 02:14:45

问题


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


回答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.




回答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? :-)



来源:https://stackoverflow.com/questions/2294100/msomevar-names-where-from-and-why

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!