匿名类型的良好命名约定

发布于 2024-07-18 05:51:13 字数 318 浏览 11 评论 0原文

匿名类型可以被视为“设置一次”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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

贪了杯 2024-07-25 05:51:13

当我在 Java Swing 应用程序中使用匿名类型时,我按以下方式使用它们:

private ActionListener [actionPerforming]Action = new ActionListener(){ /*Stuff Here*/};

这样就可以清楚地了解变量正在做什么。

When I use anonymous types in Java Swing apps I use them in the following fashion:

private ActionListener [actionPerforming]Action = new ActionListener(){ /*Stuff Here*/};

That way it is clear what the variable is doing.

鹿! 2024-07-25 05:51:13

好吧,这似乎有点矛盾,但作为开发人员,您不应该使用对您来说最重要的命名约定吗? 无论什么对你有吸引力,都会让你感到最舒服。

就我个人而言,我曾经喜欢匈牙利表示法,但最近由于它的优雅而转换为驼峰命名法(微软?)方法。 这确实是个人选择的问题。

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.

梦亿 2024-07-25 05:51:13

查看匈牙利表示法命名约定。
http://en.wikipedia.org/wiki/Hungarian_notation

nSize : integer (systems) or count (application)
iSize : integer (systems) or index (application)    
bBusy : boolean
chInitial : char
cApples : count of items
dwLightYears : double word (systems)
fBusy : boolean (flag)
fpPrice: floating-point

Check out Hungarian Notation naming convention.
http://en.wikipedia.org/wiki/Hungarian_notation

nSize : integer (systems) or count (application)
iSize : integer (systems) or index (application)    
bBusy : boolean
chInitial : char
cApples : count of items
dwLightYears : double word (systems)
fBusy : boolean (flag)
fpPrice: floating-point
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文