4

所以,我不是Hungarian Notation的忠实粉丝。今天,我公司的一位 Android 开发人员删除了此链接到有关 Android 开发的官方建议,令我惊讶的是,他们发现以 . 开头的所有字段名称很有用m

mSomeField我认为,这些名称可能有用的唯一情况是没有代码突出显示,在这种情况下,更容易看出哪些变量是本地的,哪些不是。但是现在任何 IDE 都可以显示这一点,对吧?那么,为什么在最新的 Android 代码中需要这些规则和约定呢?

更新:好吧,我的错,看起来这些建议是针对贡献者的(在这种情况下这是有道理的,他们希望保持相同的编码方式)。无论如何,有人告诉我,这经常在 Android 项目中使用。如果是这样,那么问题就在于这些项目。

4

1 回答 1

1

You would have to ask the original developers who set the standard for the project. :) This is purely speculation on my part but when you consider that Android is built on Linux and has quite a bit of C/C++ code in it, I assume that the choice to use Hungarian notation is just old-school C++ influence creeping into the Java side of the codebase. It's unfortunate in the modern world of IDE's and the need for it is a bit of a "code smell" in my opinion.

于 2014-11-11T17:36:09.920 回答