Naming convention for upper case abbreviations [cl

2019-02-03 23:49发布

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?

5条回答
Fickle 薄情
2楼-- · 2019-02-04 00:14

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

Comes from wikipedia CamelCase

查看更多
forever°为你锁心
3楼-- · 2019-02-04 00:15

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

查看更多
放荡不羁爱自由
4楼-- · 2019-02-04 00:16

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

查看更多
干净又极端
5楼-- · 2019-02-04 00:20

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()

查看更多
乱世女痞
6楼-- · 2019-02-04 00:29

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

查看更多
登录 后发表回答