如果我的 python 类名有首字母缩略词,我应该将其保留为大写,还是只保留第一个字母?

发布于 2024-09-18 11:12:21 字数 1431 浏览 2 评论 0原文

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

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

发布评论

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

评论(8

絕版丫頭 2024-09-25 11:12:22

CamelCase 名称中大写首字母缩略词的问题在于,首字母缩略词后面的单词看起来像是它的一部分,因为它以大写字母开头。此外,当您像示例中那样连续有多个时,不清楚每个从哪里开始。因此,我可能会使用你的第二个选择。

The problem with uppercase acronyms in CamelCase names is that the word following the acronym looks like a part of it, since it begins with a capital letter. Also, when you have several in a row as in your example, it is not clear where each begins. For this reason, I would probably use your second choice.

蘑菇王子 2024-09-25 11:12:22

PEP-8 没有提及任何有关首字母缩略词的内容。将首字母缩略词保持大写是最安全的(这是我最常看到的)。

The PEP-8 mentions nothing about acronyms. You would be safest to keep the acronyms uppercased (it's what I see most).

谁与争疯 2024-09-25 11:12:22

如前所述,PEP-8 要求使用大写字母作为首字母缩略词。现在,python zen 也说“可读性很重要”(对我来说,zen 优先于 PEP :-)。

在这种不清楚的情况下,我的观点是考虑编程环境中的标准,而不仅仅是语言。例如,某些 xml-http-query 类应该在 servlet 上下文(wrt XMLHttpRequest)中编写 XMLHttpQuery

我不知道您的上下文,但似乎 XMLRPCServer 存在并且您想将 ssl 附加到它。因此,您可以选择如下内容:

SSL_XMLRPCServer

它会强调 XMLRPCServer - 而无需更改它 -。
另外,你会保持接近 PEP-8 并遵循禅宗 :-)

我的 2 美分

注意:如果 XMLRPCServer 与你的类没有很强的相关性并且确实是该领域的标准,那么你需要选择另一个名称,以免混淆。

As stated already, PEP-8 says to use upper-case for acronym. Now, python zen also says "readability counts" (and for me the zen has priority over the PEP :-).

My opinion in such unclear situation is to take into account the standard in the programming context, not just the language. For example, some xml-http-query class should be written XMLHttpQuery in a servlet context (w.r.t XMLHttpRequest).

I don't know your context, but it seems XMLRPCServer exists and you want to attach ssl to it. So you could choose something like:

SSL_XMLRPCServer

It would emphasized the XMLRPCServer -without changing it-.
Also, you'd stay close to PEP-8 and follow the zen :-)

My 2 cents

Note: if XMLRPCServer is not strongly related to your class and is really a standard in the domain, then you need to choose another name, as to not be confusing.

故事和酒 2024-09-25 11:12:22

我通常使用大写缩写。 Twisted 和其他一些库也这样做。

I normally uppercase acronyms. Twisted and a few other libraries do this as well.

半步萧音过轻尘 2024-09-25 11:12:22

我有很多时间遇到这个问题。我大写缩写,但我不喜欢它,因为当你链接它们时(如你的示例),感觉不对。然而,我认为最好的做法是做出选择并坚持点击,所以至少你不知道什么时候需要引用某些东西,而无需检查它是如何编写的(这是编码标准的好处之一)

I had this problemlots of time . I uppercase Acronym but I doesn't like it because when you chain them (as in your example) it doesn't feel right. However I think the best things to do is to make a choice and stick to hit, so at least don't you know when you need to reference something how it's written without having to check (which is one of the benefit of coding standard)

蒲公英的约定 2024-09-25 11:12:22

SSL_XML_RPC_Server 的缩写和可读性怎么样?

当我出于某种原因想要避免驼峰式情况时,我经常这样做。

How about SSL_XML_RPC_Server for acronymity and readability?

It's what I often do when I want to avoid camel-case for some reason.

家住魔仙堡 2024-09-25 11:12:21

这是个人喜好的问题,但我发现第二种格式更容易阅读。事实上,您的第一种格式中有一个拼写错误(PRC 或 RPC)表明我不是唯一的人。

This is a matter of personal preference, but I find the second format much easier to read. The fact that your first format has a typo in it (PRC instead or RPC) suggests that I am not the only one.

污味仙女 2024-09-25 11:12:21

它应该是 SSLXMLRPCServer,以匹配 SimpleXMLRPCServer、CGIXMLRPCRequestHandler 等标准库类。

采用与标准库中的等效项不同的命名约定只会让人们感到困惑。

It should be SSLXMLRPCServer, to match the standard library classes like SimpleXMLRPCServer, CGIXMLRPCRequestHandler, etc.

Adopting a naming convention that differs from equivalents in the standard library is only going to confuse people.

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