语法正确的双名词标识符,复数版本

发布于 2024-08-31 13:09:18 字数 765 浏览 4 评论 0原文

考虑两个名词的复合词,在自然英语中最常以“名词 of 名词”的形式出现,例如“光的方向”、“滤波器的输出” 。编程时我们通常会写“LightDirection”和“FilterOutput”。

现在,我对复数名词有疑问。有两种情况:

1) 单数复数

“(两个)集合的并集”、“(两个)线段的交集”

例如 正确的是 SetUnion 和 SegmentIntersection 还是 SetsUnion 和 SegmentsIntersection?

2) 复数 of 复数

有两种子情况:

(a) 许多元素,每个元素都有许多相关元素,例如“过滤器的输出”

( b) 许多元素,每个元素都有一个相关元素,例如“向量的方向”

我应该使用 FilterOutputs 和 VectorDirections 还是 FiltersOutputs 和 VectorsDirections?

我怀疑第一个版本(FilterOutupts、VectorDirections)是正确的,但我认为这可能会导致歧义,例如

  • FilterOutputs - 单个过滤器的许多输出或许多过滤器的许多输出?
  • LineSegmentProjections - 许多线段的投影或单个线段的许多投影?

我应该遵循哪些一般规则?

Consider compounds of two nouns, which in natural English would most often appear in the form "noun of noun", e.g. "direction of light", "output of a filter". When programming, we usually write "LightDirection" and "FilterOutput".

Now, I have a problem with plural nouns. There are two cases:

1) singular of plural

e.g. "union of (two) sets", "intersection of (two) segments"

Which is correct, SetUnion and SegmentIntersection or SetsUnion and SegmentsIntersection?

2) plural of plural

There are two subcases:

(a) Many elements, each having many related elements, e.g. "outputs of filters"

(b) Many elements, each having single related element, e.g. "directions of vectors"

Shall I use FilterOutputs and VectorDirections or FiltersOutputs and VectorsDirections?

I suspect correct is the first version (FilterOutupts, VectorDirections), but I think it may lead to ambiguities, e.g.

  • FilterOutputs - many outputs of a single filter or many outputs of many filters?
  • LineSegmentProjections - projections of many segments or many projections of a single segment?

What are the general rules, I should follow?

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

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

发布评论

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

评论(8

蓬勃野心 2024-09-07 13:09:18

这个问题背后存在语法误解。当我们将以下形式的短语转换

1. X of Y

2. Y X

Y 时,语法角色从所有格 (1) 中的名词变为定语 (2) 中的形容词。因此,虽然在 (1) 中可以将 X 和 Y 复数,但在 (2) 中只能将 X 复数,因为 (2) 中的 Y 是形容词,而形容词没有 语法编号

因此,例如,SetsUnion 不符合英语。如果它适合你,你可以自由使用它,但你会导致可读性下降,我建议不要这样做。

后记

特别是,考虑另外两种所有格结构,首先是使用所有格代词“its”的老式结构,单数:

3a. Y, its X

等效复数:

4a. Ys, their X

及其缩写,其中 4b 比 3b 少见得多:

3b. Y's X
4b. Ys' X

这里,SetsUnion 表明它是单数所有格类型 (3) Set's Union (=Set, its Union) 的呈现,您打算在其中传达复数所有格 (4) Sets, their Union(缩写为不太常见的Sets' Union)。

所以它是积极误导的。

There's a grammatical misunderstanding lying behind this question. When we turn a phrase of form:

1. X of Y

into

2. Y X

the Y changes grammatical role from a noun in the possessive (1) to an adjective in the attributive (2). So while one may pluralise both X and Y in (1), one may only pluralise X in (2), because Y in (2) is an adjective, and adjectives do not have grammatical number.

Hence, e.g., SetsUnion is not in accordance with English. You're free to use it if it suits you, but you are courting unreadability, and I advise against it.

Postscript

In particular, consider two other possessive constructions, first the old-fashioned construction using the possessive pronoun "its", singular:

3a. Y, its X

the equivalent plural:

4a. Ys, their X

and their contractions, with 4b much less common than 3b:

3b. Y's X
4b. Ys' X

Here, SetsUnion suggests it is a rendering of the singular possessive type (3) Set's Union (=Set, its Union), where you intended to communicate the plural possessive (4) Sets, their Union (contracted to the less common Sets' Union).

So it's actively misleading.

日裸衫吸 2024-09-07 13:09:18

使用名词的复数形式会使它们更难以阅读。

当你有很多东西时,它们通常存储在数据结构中 - 数组、列表、映射、集合等。通常称为集合或 抽象数据类型。项目集合的接口通常是编程环境的一部分(例如java和.net中的集合,C++中的STL),并且开发人员很好地理解涉及项目的数量。

您可以避免名词复数,并明确您正在处理多个数量的事实,并通过合并集合名称来指示如何访问它们。例如,

  • VectorDirectionList - 列出向量及其方向,例如某种 Pair 类型。如果您有一个 VectorDirection,结合了 Vector 和 Direction,效果特别好。
  • VectorDirectionMap - 如果矢量方向是从矢量映射的。

因为它是一个集合类型,所以处理多个对象被理解为它是集合类型所特有的。然后将其放入与 SetUnion 相同的类中 - 一个并集始终涉及至少 2 个集合,并且 VectorDirectionList 明确表明可以有多个 VectorDirection。

我同意避免同音异义词,因为该单词具有多个词类,例如 Filter,(实际上是 Set,尽管在我看来 Set 不会真正在类名中用作动词,所以我将其解释为名词。 )我最初使用 FilterOutput 作为示例来编写此内容,但读起来不太好。使用 Filter 的复合可能有助于消除歧义 - 例如 ImageFilterOutputs (或应用我自己的建议,这将是 ImageFilterOutputList。)

当您认为类的实例本身始终是一项时,避免使用类名的复数形式似乎很自然 - “一个实例”。如果我们使用复数名称,那么我们会得到不匹配 - 一个实例试图暗示它是多个事物 - 它本身只是一件事,即使它引用了多个其他事物。上面的集合命名建立在这个基础上 - 你有一个实例,它是一个列表,一个地图等,所以不存在不匹配。

我假设您正在谈论编程语言结构,尽管同样的想法也适用于表/视图。这些被理解为涉及项目的数量,因此即使它们存储多行,表名称也通常是单一的(客户、订单、项目)。多对多映射表通常是相关实体的组合,例如将订单与项目相关联 - OrderItem。根据我的经验,使用复数表名会使 SQL 难以阅读。

总而言之,我会避免使用复数形式,因为它们会使阅读变得更加困难。肯定有一些情况是不可避免的 - 使用复数形式比创建嵌套实体和集合的巨大名称更具可读性,但这些是例外而不是规则。

Using plural forms of nouns can make them more difficult to read.

When you have a number of things, they are usually stored in a datastructure - an array, a list, a map, set, etc.. generically called a collection or abstract data type. The interface to a collection of items is typically part of the programming environment (e.g. Collections in java and .net, STL in C++) and is well understood by developers to involve quantities of items.

You can avoid pluralizing your nouns, and make the fact that you are dealing with multiple quantities explicit, and indicate how they are accessed by incorporating the name of the collection. For example,

  • VectorDirectionList - the vectors and their directions are listed, e.g. some kind of Pair type. Works particularly well if you have a VectorDirection, combining a Vector and a Direction.
  • VectorDirectionMap - if the vector directions are mapped from vector.

Because it's a collection type, dealing with multiple objects is understood as it is endemic to a collection type. It then puts it in the same class as SetUnion - a union always involves at least 2 sets, and a VectorDirectionList makes it clear there can be more than one VectorDirection.

I agree about avoiding homonyms where the word has more than one word class, e.g. Filter, (and actually, Set, although to my mind Set would not really be used in a class name as a verb, so I interpret it as a noun.) I originally wrote this using FilterOutput as an example, but it didn't read well. Using a compound for Filter may help disambiguate - e.g. ImageFilterOutputs (or applying my own adivce, this would be ImageFilterOutputList.)

Avoiding plural forms with class names seems natural when you consider that an instance of a class is itself always one item - "an instance". If we use a plural name, then we get a mismatch - an instance trying to imply that it is multiple things - it itself is just one thing, even if it references multiple other things. The collection naming above builds on this - you have an instance which is a list, a map etc so there is no mismatch.

I'm assuming you are talking about programming language constructs, although the same thinking applies to tables/views. These are understood to involve quantities of items and table names are consequently often singlular (Customer, Order, Item) even though they store multiple rows. Many-to-Many Mapping tables are usually compounds of the entities being related, e.g. relating orders to items - OrderItem. In my experience, using plurals for table names makes the SQL difficult to read.

To sum up, I would avoid plural froms as they make reading harder. There are sure to be cases where they are unavoidable - where using the plural form is more readable than creating a huge name of nested entities and collections, but these are the exception than the rule.

荆棘i 2024-09-07 13:09:18

除非您被约定驱动的系统(Ruby on Rails、cakePHP 等)所困扰,否则为什么不使用 OutputsOfFilters、UnionOfSets 等呢?它们可能不传统,但可能更清晰。

例如,很明显 ProjectionOfLineSegments 和 ProjectionsOfLineSegment 是不同的东西,甚至是 ProjectionsOfLineSegments....

Unless you're getting hamstrung by a convention driven system (ruby on rails, cakePHP etc), why not use OutputsOfFilters, UnionOfSets etc? They may not be conventional but they may be clearer.

For example its pretty clear that ProjectionOfLineSegments and ProjectionsOfLineSegment are different things or even ProjectionsOfLineSegments....

单挑你×的.吻 2024-09-07 13:09:18

我应该遵循哪些一般规则?

  1. 让它清晰——对于视觉和听觉思考者来说。
  2. 使其具体但准确
  3. 使其通过“拥挤的房间”或“紧急电话”测试

以 SetsUnion 为例进行说明:

  • “SetsUnion”就出来了;它很容易被误认为是拼写错误,并且说出它(即使在你的脑海中)也会将其与“Set's Union”(或更糟)混淆。

  • 复数也是隐含的,所以第二个“s”是多余的。
    SetUnion 更好,但仍然不明确。

  • UnionOfSets 更清晰,应该是最低标准。

  • 但是到目前为止,所有这些都是毫无用处的模糊(除非您正在研究纯数学理论)。
    该术语确实应该具体。比如“红车”、“在深奥上花了太多时间的程序员”等等
    这些都是集合的并集,但它们告诉您一些有用的信息。 ;-)

.
最后,Phil Factor 有权利。转述一下:

您能否在拥挤的房间里大声喊出一个(术语)并让另一边的听众输入并成功(使用)该术语?

试着在拥挤的爱尔兰酒吧里大喊“SetsUnion”,甚至“UnionOfSets”。 ;-)

What are the general rules, I should follow?

  1. Make it Clear -- for both visual and aural thinkers.
  2. Make it Specific but Accurate.
  3. Make it pass the "crowded room" or "emergency phone call" test.

To illustrate with the SetsUnion example:

  • "SetsUnion" is right out; It's easily confused for a typo and speaking it (even in your head) will confuse it for "Set's Union" (Or worse).

  • The plural is also implied, so the 2nd 's' is redundant.
    SetUnion is better but still ambiguous.

  • UnionOfSets is clearer and should be the bare minimum standard.

  • But all of these, so far, are uselessly vague (unless you are working with pure mathematical theory).
    The term really should be specific. For example, "Red cars", "Programmers who spent too much time on esoterica", etc.
    These are all unions of sets, but they tell you something useful. ;-)

.
Finally, Phil Factor had the right of it. To paraphrase:

Can you shout a (term) out across a crowded room and have it keyed in, and successfully (used), by a listener at the other side?

Try yelling, "SetsUnion," or even, "UnionOfSets," across a packed Irish bar. ;-)

土豪 2024-09-07 13:09:18

Union() 有什么问题吗?

而且,“集合的并集”变成“集合的并集”(两个集合的并集是...);我确信我不是唯一一个可以使用 CamelsCase 但不可以使用 CamelsCaseMinusApostropes 的人。如果需要撇号才能有意义,请不要使用它。 Set.Union() 读起来与“集合的并集”完全相同。

数学上也会说“A 和 B 的(集合)并集”,或者很少说“A 和 B 的(集合)并集”。 “A 和 B 的集合并集”毫无意义!

大多数人还会看到Vector[]向量Directions[] vectorDirections并假设向量[i]对应于vectorDirections[i]。如果事情真的变得不明确,我会使用诸如 vector_by_index 和 vectorDirection_by_index 之类的东西。然后你就可以有 Map; output_by_filterMap; outputs_by_filter,这使得键是什么非常明显(这在 Objective-C 中非常重要,因为键或值的类型完全不明显)。

如果你真的想要,你可以添加一个 s 并得到 paths_by_index,但是一致性会给你愚蠢的outputs_by_filter。

当然,正确的是 struct FilterState { Filter filter; 之类的东西。 Output[] 输出; }; FilterState[] 过滤器状态;

What's wrong with Union()?

Moreover, "union of sets" turns into "sets' union" (the two sets' union is ...); I'm sure I'm not the only person who's okay with CamelCase but not CamelsCaseMinusApostrophes. If it needs an apostrophe to make sense, don't use it. Set.Union() reads exactly like "union of set(s)".

Mathematations will also say "the (set) union of A and B", or rarely "A and B's (set) union". "The sets' union of A and B" makes no sense!

Most people will also see Vector[] vectors and Directions[] vectorDirections and assume that vectors[i] corresponds to vectorDirections[i]. If things really get ambiguous, I use something like vector_by_index and vectorDirection_by_index. Then you can have Map<Filter,Output> output_by_filter or Map<Filter,Output[]> outputs_by_filter, which makes it very obvious what the key is (this is very important in Objective-C where it's completely non-obvious what type the keys or values are).

If you really want, you can add an s and get vectors_by_index, but then consistency gives you the silly outputss_by_filter.

The right thing is, of course, something like struct FilterState { Filter filter; Output[] outputs; }; FilterState[] filterStates;.

淡看悲欢离合 2024-09-07 13:09:18

1)我会使用 SetUnion 和 SegmentIntersection 因为我认为在这种情况下无论如何都隐含了复数,而且这样看起来更好。

2)同样,出于同样的原因,我将使用 FilterOutputs 和 VectorDirections。如果您想更具体,您可以随时使用 MultipleFilterOutputs。

但最终这完全取决于您的个人喜好。

1) i would use SetUnion and SegmentIntersection because i think in this case the plurality is implied anyway and it just looks nicer that way.

2) again, i would use FilterOutputs and VectorDirections, for the same reason. you could always use MultipleFilterOutputs if you want to be more specific.

but ultimately it's entirely down to your personal preference.

无戏配角 2024-09-07 13:09:18

我认为虽然一般命名约定和一致性很重要,但在非常非常严格/棘手的算法中,清晰度应该胜过约定。如果有帮助,请使用veryLongAndDescriptiveIdentifiers。

I think that while general naming conventions and consistency are important, but in a very very tight/tricky algorithm, clarity should trump convention. If it helps, use veryLongAndDescriptiveIdentifiers.

哥,最终变帅啦 2024-09-07 13:09:18

我建议第一个单词使用单数:SetUnionVectorDirections 等。

在 IDE 中进行快速类搜索,查找:Strings*、Sets*、Vectors*、集合*

无论如何,无论您选择什么,在整个应用程序中保持一致

I'd suggest singular for the first word: SetUnion, VectorDirections, etc.

Do a quick class search in your IDE, for: Strings*, Sets*, Vectors*, Collections*

Anyway, whatever you choose, be consistent throughout the whole application.

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