命名枚举类型

发布于 2024-07-19 05:04:29 字数 289 浏览 3 评论 0原文

如果您有一组相关的单词(例如“行”和“列”或“开”和“关”),您如何找到描述这些单词的集合词? 具体来说,如何命名枚举?

如果我有“红色”、“绿色”和“蓝色”,那么合理的枚举名称可能是“颜色”。 “On”和“Off”的值可能有一个合理的枚举名称“Power”。 但是如何命名可以具有“Row”或“Column”值的枚举呢?


对于“你如何命名行或列枚举?”有几个很好的答案 - 笛卡尔和索引类型。

寻找一般的集体单词怎么样?有没有任何资源,或者你只需​​要擅长英语/知道很多单词?

If you have a set of related words (e.g. Row & Column or On & Off), how do you find the collective word that describes those words? Specifically, how do you name an enum?

If I have "Red", "Green" and "Blue", a sensible enum name might be "Color". Values of "On" and "Off" might have a sensible enum name of "Power". But how do I name the enum that can have a value of "Row" or "Column"?


Couple of good answers to "What do you name a Row or Column enum?" - Cartesian and IndexType.

What about finding collective words in general - are there any resources out there or do you just have to be good at English / know lots of words?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(9

韬韬不绝 2024-07-26 05:04:29

尝试使用指示枚举用途的名称,例如

public enum CountMethod 
{
    Row,
    Column
}

Try using a name which indicates what the enum is used for, e.g

public enum CountMethod 
{
    Row,
    Column
}
好菇凉咱不稀罕他 2024-07-26 05:04:29

有一个名为 WordNet 的软件,它基本上将每个英语单词分类为复杂的类层次结构,并为其构建了软件,该软件可以接受两个单词并返回它们最早的公共超类(wordnet 语言中的上位词)。

在这种情况下,查询红色一词将返回类似

red, redness
   => chromatic color, chromatic colour, spectral color, spectral colour
       => color, colour, coloring, colouring
           => visual property
               => property
                   => attribute
                       => abstraction, abstract entity
                           => entity

查询蓝色的结果,

blue, blueness
   => chromatic color, chromatic colour, spectral color, spectral colour
       => color, colour, coloring, colouring
           => visual property
               => property
                   => attribute
                       => abstraction, abstract entity
                           => entity

因此您知道,描述红色或蓝色的最准确方法是“彩色”

There is a software called WordNet which has essentially classified every english word in a complex class hierarchy and has software built for it which can take two words and return their earliest common superclass (hypernym in wordnet language).

In this case, querying for the word red would return something like

red, redness
   => chromatic color, chromatic colour, spectral color, spectral colour
       => color, colour, coloring, colouring
           => visual property
               => property
                   => attribute
                       => abstraction, abstract entity
                           => entity

Querying for blue gives

blue, blueness
   => chromatic color, chromatic colour, spectral color, spectral colour
       => color, colour, coloring, colouring
           => visual property
               => property
                   => attribute
                       => abstraction, abstract entity
                           => entity

So you know, the most accurate way to describe red or blue is 'chromatic color'

远山浅 2024-07-26 05:04:29

对于(行|列)我通常使用“IndexType”或类似的东西。 正如我所看到的,行或列是同一数据结构中的两个不同索引。

我发现自己主要在编写基于表的数据结构时使用它,它可以让您通用地编写绝大多数代码,而不管您是在行还是列上操作,而只是在数据结构中进行一系列索引。 然后,要执行特定于行或列的操作,您只需调用具有要使用的特定索引类型的通用操作。

如果它的范围限定在一个类中,那么效果最好

Table.IndexType or Grid.IndexType (etc.)

For (Row | Colum) I usually use 'IndexType' or something like that. As I see the row or columns being two different indexes into the same data structure.

I find myself using it primarily when I'm writing a table-based data structure it lets you write the vast majority of your code generically without regard to whether you're operating on rows or columns, just a range of indexes into the data structure. Then to do a row or column specific operation you just call the generic operation with the specific index type to use.

It works best if it is scoped to a class so that it's

Table.IndexType or Grid.IndexType (etc.)
从来不烧饼 2024-07-26 05:04:29

我首先想到的是“笛卡尔”。 正如

public enum Cartesian
{
   Row, Column
}

这背后的原因是因为行/列最接近地表示网格系统的笛卡尔坐标。

The first thing that comes to my mind is "Cartesian". As in

public enum Cartesian
{
   Row, Column
}

The reasoning behind this is because row/column most closely suggests the Cartesian Coordinates of a grid system.

零時差 2024-07-26 05:04:29

对英语词汇的良好了解对此会有所帮助,但是该语言中有大量的集体名词,即使是大多数母语人士也完全不知道。 例如,有多少人碰巧知道乌鸦的集体名词是“谋杀”? 顺便说一句,斯汀在他的歌曲“All This Time...”中使用了这个词。

我最初建议笛卡尔坐标是因为它类似于数学中的笛卡尔坐标。 辅助问题,集体词呢,本身就很有趣,因此为了任何可能想要了解这一点的人的利益,来自维基百科:

来自 AH 的集体名词

来自 AH 的集体名词IZ

也许那里有一些东西可能会触发一个好的枚举名称!

A good knowledge of English vocabulary would be helpful for this, but there are a plethora of collective nouns in the language that even most native speakers are completely ignorant of. For example, how many people happen to know that the collective noun for crows is "murder"? Sting used this word in his song "All This Time...", btw.

I suggested Cartesian originally because of the analog to cartesian coordinates in mathematics. The ancillary question, what about collective words, is interesting in and of itself, so for the benefit of anyone who might want to scope this out, from Wikipedia:

Collective Nouns from A-H

Collective Nouns from I-Z

Maybe there is something there that might trigger a good enum name!

时光礼记 2024-07-26 05:04:29

您需要一个描述枚举内各个元素的名称。 例如,您的行、列示例或两个笛卡尔元素,因此笛卡尔将是一个很好的名称。 如果您有一个硬件商店的零件列表作为枚举,那么一个好的名称是 HardwareStoreParts 等。如果您有一个枚举,例如 shoes、graphs、elephant、blue、pluto、Martha Stewart< /code>,那么你做错了什么。 如果您想不出这些项目的术语,也许您正在尝试强制枚举适应它不适合的东西。

You want a name that describes what the individual elements inside the enum are. For example your Row, Column example or both Cartesian elements, so Cartesian would be a good name for it. If you had a list of parts for a hardware store as an enum, a good name for it would be HardwareStoreParts, etc. If you have a enum of things like shoes, graphs, elephants, blue, pluto, Martha Stewart, then you're doing something wrong. If you can't think of a term for the items perhaps you're trying to force the enum to fit something it's not made for.

岁月打碎记忆 2024-07-26 05:04:29

另一种可能性:

public enum Mapping
{
   Row, Column
}

Another possibility:

public enum Mapping
{
   Row, Column
}
梦开始←不甜 2024-07-26 05:04:29

想想它将如何使用。 您想要描述什么属性?

您选择的术语应该反映这些值的实际使用情况。 对于 API 的用户来说,这应该是自然的并且有些可猜测的。

例如,这些可能相当不错:

widget.IndexMethod = IndexMethod.Row
widget.CountBy = CountMethod.Column

沿着同样的路线,我认为在大多数情况下笛卡尔是一个糟糕的选择。 笛卡尔既不是自然的也不是可猜测的,除非您正在处理技术图形功能或其他东西。

Think about how it will be used. What property or properties are you looking to describe?

The term you settle on should be reflective of the actual use of the values. It should be natural and and somewhat guessable for users of the API.

For example, these are probably pretty good:

widget.IndexMethod = IndexMethod.Row
widget.CountBy = CountMethod.Column

Along these same lines, I think Cartesian would be an awful choice in most circumstances. Cartesian is neither natural nor guessable, unless you're dealing with a technical graphing feature or something.

一杯敬自由 2024-07-26 05:04:29

我尝试想出一个在实际使用枚举时最有意义的名称。 根据上下文,可能类似于:

Table.ROW

或者相当不同的东西,例如:

SortMode.ROW

I try to come up with a name that makes most sense when the enum is actually used. Depending on the context that might be something like:

Table.ROW

Or something rather different like:

SortMode.ROW
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文