命名约定中的撒克逊属格?

发布于 2024-08-06 18:40:37 字数 498 浏览 4 评论 0原文

当名称包含撒克逊属格(例如“验证任务的优先级”和“更改参数的优先级”或“增加操作的延迟”)时,您如何称呼您的函数?

你去掉撇号吗? verifyTasksPriority()、changeArgumentsPriority()、increaseActionsDelay()

您是否同时删除了撇号和“s”? verifyTaskPriority()、changeArgumentPriority()、increaseActionDelay()

您是否将撒克逊属格替换为“of”? verifyPriorityOfTask()、changePriorityOfArgument()、increaseDelayOfAction()

我不喜欢第一个选项,因为听起来该函数适用于多种事物,而不仅仅是一种事物。 我不喜欢第二种选择,因为它听起来不自然。我不喜欢第三个选项,因为函数名称中的单词“of”听起来不太正确。

您使用什么选项?

What do you call your functions when names that contain a saxon genitive like "Verify Task's Priority" and "Change Argument's Priority" or "Increase Action's Delay"?

Do you drop the apostrophe? verifyTasksPriority(), changeArgumentsPriority(), increaseActionsDelay()

Do you drop both the apostrophe and the "s"? verifyTaskPriority(), changeArgumentPriority(), increaseActionDelay()

Do you replace the saxon genitive with "of"? verifyPriorityOfTask(), changePriorityOfArgument(), increaseDelayOfAction()?

I don't like the first option because it sounds like the function works on multiple things rather than just one thing.
I don't like the second option because it doesn't sound natural. I don't like the third option because the word, of, in a function name just doesn't sound right.

What option do you use?

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

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

发布评论

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

评论(4

原来是傀儡 2024-08-13 18:40:37

我用的是第二个。对我来说听起来不错。将“任务优先级”视为一个复合词,如“吸尘器”。

I use the second. It sounds good to me. Think of "Task Priority" as a compound word like "vacuum cleaner".

青衫负雪 2024-08-13 18:40:37

我发现第二和第三对我来说听起来不错,并且具有描述性。我使用第二个选项。第一个选项可能会令人困惑,因为它似乎表明它对集合而不是单个项目进行操作(例如,任务而不是任务)。

然而,我并没有意识到我正在做撒克逊属格编程。我会立即将其添加到我的简历中。

I find that numbers two and three sound fine to me, and are descriptive. I use the second option. The first option could possibly be confusing since it seems to indicate that it operates on a collection rather than a single item (Tasks instead of Task, for instance).

I was not, however, aware that I was doing Saxon genitive programming; I'll add that to my resume immediately.

柏拉图鍀咏恒 2024-08-13 18:40:37

在寻找撒克逊属格的一些微妙之处时,这个老问题引起了我的注意。根据华尔街英语,萨克森属格用于描述占有:

撒克逊属格用“of”一词代替来表示占有。它是
主要用来指人拥有的东西,但也可以指
用于动物、组织甚至一些时间表达。到
创建我们将 ' 添加到名称中的撒克逊属格。例如:

这是约翰的车。 = 这是约翰的车。

在同一页面的下方,我们发现以下内容:

何时不使用撒克逊属格

我们通常不使用撒克逊语
与对象的所有格。在这种情况下,我们更喜欢“of”。例如:

房子的门。 (不是“房子的门”。)

笔盖。 (不是“笔盖”。)

路的尽头。 (不是“路的尽头”。)

一般来说,如果您不确定是否使用 saxon
所有格,使用 'of' 更安全。

这意味着我们不会说任务的优先级操作的延迟。因此,第一个选项应该被完全消除。

第三个选项在语法上是正确的,但听起来有些笨拙。

第二个选项使用复合名词。正如该页面上所解释的,构建复合名词有很多可能性,第一个给出的是名词 + 名词的组合:

  • 卧室
  • 水箱
  • 摩托车
  • 打印机墨盒

我们还可以想到计算机编程中使用的其他示例,例如:状态代码、设计模式、语法错误等。

因此,第二种选择是可行的方法。

由于我对命名约定非常迂腐,因此我想分享我的发现并进一步支持之前的答案。

This old question drew my attention when searching for some subtleties of the Saxon Genitive. According to Wall Street English the Saxone Genitive is used to describe possesion:

The Saxon Genitive substitutes the word ‘of’ to show possession. It’s
used mainly to refer to things owned by people, but it can also be
used with animals, organizations and even some time expressions. To
create the saxon genitive we add ‘s to a name. For example:

This is John’s car. = This is the car of John.

Further down on the same page we find the following:

When not to use the Saxon Genitive

We don’t normally use the saxon
genitive with objects. In this case we prefer ‘of’. For example:

The door of the house. (NOT ‘The house’s door’.)

The lid of the pen. (NOT ‘The pen’s lid’.)

The end of the road. (NOT ‘The road’s end’.)

Generally speaking, if you’re not sure whether or not to use the saxon
genitive, it’s safer to use ‘of’.

This means we wouldn't say task's priority or action's delay. Therefore the first option should be eliminated altogether.

The third option is grammatically correct, but sounds something unwieldy.

The second option uses compound nouns. As explained on that page, there are many possibilities to build a compound noun, the first given is a combination of noun + noun:

  • bedroom
  • water tank
  • motorcycle
  • printer cartridge

We can also think of other examples used in computer programming, like: status code, design pattern, syntax error, etc.

The second option is thus the way to go.

Since I'm very pedantic about naming conventions I wanted to share my findings and further support the previous answers.

别靠近我心 2024-08-13 18:40:37

如果您需要使函数名称长几个单词以区分它们,则可能会失败 单一职责原则,因此您建议的选项都没有帮助。

我主要使用面向对象语言编写面向对象代码,因此要验证任务的优先级,您需要使用 task.verifyPriority(),尽管通常只使用 task.verify() > 作为公共方法。

验证优先级可能涉及其他逻辑 - 例如,如果任务所有者是 Bob,则优先级只能为 7。将 Bob 的优先级 7 任务之一的所有者设置为 Anna 会导致不一致,但是当您更改所有者以及 verifyPriority() 时,是否会调用 verifyOwner() code> 当您更改优先级时,即使它们具有相同的逻辑?

我发现,减少 API 的具体实现细节会产生更具延展性的代码。

在非面向对象语言中,我通常使用 __ 所以 tman_task_verify (task_t* self ) 来验证任务管理器中的任务对象库来验证自身。

If you need to make your function names several words long to distinguish them from each other, you are probably failing in the single responsibility principle so none of your suggested options will help.

I write OO code, mainly in OO languages, so to verify the priority of a task you'd have task.verifyPriority(), though usually just have task.verify() as the public method.

Verifying the priority may involve other logic - say the priority can only be 7 if the task's owner is Bob. Setting the owner of one of Bob's priority 7 tasks to Anna would make it inconsistent, but would you have verifyOwner() to be called when you change the owner as well as verifyPriority() for when you change the priority, even if they had the same logic?

I've found that making APIs less specific to the detail of the implementation leads to more malleable code.

In non-OO languages I usually use <library>_<Noun>_<Verb> so tman_task_verify ( task_t* self ) to verify the task object in the task manager library to verify itself.

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