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?
由于匿名类型在实例化后无法更改,因此不应根据其意图进行命名?
3 个解决方案
#1
When I use anonymous types in Java Swing apps I use them in the following fashion:
当我在Java Swing应用程序中使用匿名类型时,我以下列方式使用它们:
private ActionListener [actionPerforming]Action = new ActionListener(){ /*Stuff Here*/};
That way it is clear what the variable is doing.
这样很清楚变量在做什么。
#2
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.
就个人而言,我曾经偏爱匈牙利表示法,但我最近因其优雅而转换为camelCase(微软?)方法。真的,这是个人选择的问题。
#3
Check out Hungarian Notation naming convention. http://en.wikipedia.org/wiki/Hungarian_notation
查看匈牙利表示法命名约定。 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
#1
When I use anonymous types in Java Swing apps I use them in the following fashion:
当我在Java Swing应用程序中使用匿名类型时,我以下列方式使用它们:
private ActionListener [actionPerforming]Action = new ActionListener(){ /*Stuff Here*/};
That way it is clear what the variable is doing.
这样很清楚变量在做什么。
#2
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.
就个人而言,我曾经偏爱匈牙利表示法,但我最近因其优雅而转换为camelCase(微软?)方法。真的,这是个人选择的问题。
#3
Check out Hungarian Notation naming convention. http://en.wikipedia.org/wiki/Hungarian_notation
查看匈牙利表示法命名约定。 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