大写缩写的命名约定

发布于 2024-12-17 21:04:59 字数 177 浏览 5 评论 0原文

应该调用返回 XML 流的方法

public Stream getXmlStream();

还是改为调用

public Stream getXMLStream();

您对此有何看法?什么被认为是最佳实践?

Should a method that returns an XML stream be called

public Stream getXmlStream();

or instead

public Stream getXMLStream();

What's your opinion about that? What's considered best practice?

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

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

发布评论

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

评论(5

情痴 2024-12-24 21:04:59

没有一个正确的答案。此 wiki 摘录很有帮助:

编程标识符通常需要包含首字母缩写词和首字母缩写词
已经是大写的,例如“old HTML file”。类推
根据标题大小写规则,自然驼峰大小写渲染将具有
缩写全部大写,即“oldHTMLFile”。然而,
当两个首字母缩写词同时出现时(例如,
“parse DBM XML”将变为“parseDBMXML”)或当标准
要求使用小驼峰式大小写,但名称以缩写开头
(例如“SQL 服务器”将变为“SQLServer”)。为此,一些
程序员更喜欢将缩写视为小写字母
单词并写入“oldHtmlFile”、“parseDbmXml”或“sqlServer”。

There is no one correct answer. This wiki extract is helpful:

Programming identifiers often need to contain acronyms and initialisms
which are already in upper case, such as "old HTML file". By analogy
with the title case rules, the natural camel case rendering would have
the abbreviation all in upper case, namely "oldHTMLFile". However,
this approach is problematic when two acronyms occur together (e.g.,
"parse DBM XML" would become "parseDBMXML") or when the standard
mandates lower camel case but the name begins with an abbreviation
(e.g. "SQL server" would become "sQLServer"). For this reason, some
programmers prefer to treat abbreviations as if they were lower case
words and write "oldHtmlFile", "parseDbmXml" or "sqlServer".

明媚殇 2024-12-24 21:04:59

“惯例”就是这样——它不是“规则”。但是,我强烈认为 getXmlStream() 是最好的选择。考虑多个此类术语:将 getSQLDBIOXML()getSqlDbIoXml() 进行比较

A "convention" is just that - it's not a "rule". However, I feel strongly that getXmlStream() is the best option. Consider multiple such terms: compare getSQLDBIOXML() to getSqlDbIoXml()

皇甫轩 2024-12-24 21:04:59

您可能应该选择getXmlStream。想想 parseDBMXML 或更复杂的示例,这些示例会使代码不可读。

来自维基百科 CamelCase

You should probably go for getXmlStream. Think of parseDBMXML or more complicated examples that make the code unreadable.

Comes from wikipedia CamelCase

望喜 2024-12-24 21:04:59

我并不是说应该是这样,但对于某些人来说,他们可以自动调整/期望当存在一连串大写字母后跟小写字母时,某处会出现首字母缩略词。我的意见是使用getXmlStream()——我认为对大多数人来说更容易与立即能够轻松读取 getXMLStream() 的人数相比......

I'm not saying it should be this way but for some, they can automatically adjust/expect that when there's a sequential string of upper-cased letters followed by lower-cased letters there is an acronym somewhere. My opinion is to go with getXmlStream() --it's something that I think is something easier for most people to read, compared to the number of those instantly able to read getXMLStream() with ease..

空城之時有危險 2024-12-24 21:04:59

建议使用 public Stream getXMLStream();
缩写最好保持原意

using public Stream getXMLStream(); will be advisable
Its better to keep original meaning of abbreviation

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