匿名类型的良好命名约定
匿名类型可以被视为“设置一次”Object
类型,而普通的旧 Object
或 Variant 可以设置多次。 对象或变体的寿命往往很短,而匿名类型的寿命预计会更长,因此传达意图非常重要。
使用匿名类型时,您使用什么命名约定来传达意图?
我搜索了“命名约定”问题,对于与对象或变体不同的匿名类型,答案仍然难以捉摸。
匈牙利表示法就像舞会之夜的一个巨大的鼻子疙瘩,所以可能没有什么用处。
由于匿名类型一旦实例化就无法更改,因此不应该根据其意图来命名吗?
An anonymous type can be thought of as a "Set Once" Object
type, whereas an plain old Object
or Variant can be set many times. An object or variant tends to be short lived, while an anonymous type is expected to live longer, making it important to communicate intent.
What naming convention do you use to communicate intent when using anonymous types?
I've searched "Naming Convention" questions and the answer is still elusive with regard to Anonymous Types which are different from objects or variants.
Hungarian Notation is like a giant nose pimple on prom night, so probably nothing useful there.
Since an anonymous type cannot be changed once it is instantiated, shouldn't be named according to its intent?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当我在 Java Swing 应用程序中使用匿名类型时,我按以下方式使用它们:
这样就可以清楚地了解变量正在做什么。
When I use anonymous types in Java Swing apps I use them in the following fashion:
That way it is clear what the variable is doing.
好吧,这似乎有点矛盾,但作为开发人员,您不应该使用对您来说最重要的命名约定吗? 无论什么对你有吸引力,都会让你感到最舒服。
就我个人而言,我曾经喜欢匈牙利表示法,但最近由于它的优雅而转换为驼峰命名法(微软?)方法。 这确实是个人选择的问题。
Well, it may seem somewhat of an oxymoron but shouldn't you use whatever naming convention means the most to you, as the developer? Whatever appeals to you, makes you most comfortable..
Personally, I used to favour Hungarian Notation but I was recently converted to the camelCase (Microsoft?) method by the elegance of it. It's a matter of personal choice, really.
查看匈牙利表示法命名约定。
http://en.wikipedia.org/wiki/Hungarian_notation
Check out Hungarian Notation naming convention.
http://en.wikipedia.org/wiki/Hungarian_notation