39

是否应该调用返回 XML 流的方法

public Stream getXmlStream();

或者相反

public Stream getXMLStream();

你对此有何看法?什么是最佳实践?

4

5 回答 5

38

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

编程标识符通常需要包含已经大写的首字母缩写词和首字母缩写词,例如“旧 HTML 文件”。类比标题大小写规则,自然驼峰式渲染会有全部大写的缩写,即“oldHTMLFile”。但是,当两个首字母缩略词一起出现时(例如,“parse DBM XML”将变为“parseDBMXML”)或当标准要求使用小写字母但名称以缩写开头时(例如,“SQL server”将变为“SQLServer ”)。出于这个原因,一些程序员更喜欢把缩写词当作小写单词,写成“oldHtmlFile”、“parseDbmXml”或“sqlServer”。

于 2011-11-26T09:00:26.720 回答
18

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

于 2011-11-26T09:26:54.030 回答
13

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

Comes from wikipedia CamelCase

于 2011-11-26T09:01:47.147 回答
7

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..

于 2011-11-26T09:01:17.613 回答
1

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

于 2011-11-26T09:12:15.480 回答