java-当我们在类名中使用“ iOS”作为单词时,是否应该将“ i”大写?

前端之家收集整理的这篇文章主要介绍了java-当我们在类名中使用“ iOS”作为单词时,是否应该将“ i”大写? 前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

某些品牌名称实际上并不喜欢使用首字母大写,更改名称可能会使外观看起来完全不同,尤其是对于“ iOS”而言.还有更多类似“ mCore”,“ macOS”等等.关于班级名称,我应该将首字母大写还是保留原样?

例如“ iOSCompatProxy”和“ IOSCompatProxy”

最佳答案
对于这种类型的类名,没有普遍遵循的约定.甚至常规的大写缩写(如“ XML”)也会导致不一致.从the official JDK class list来看,我看到与XmlSomething一样多的名为XMLSomething的类.

Google在Google Java Style Guide中处理了这个主题,他们提出了一种将文本转换为类名的方案:

Sometimes there is more than one reasonable way to convert an English phrase into camel case,such as when acronyms or unusual constructs like “IPv6” or “iOS” are present. To improve predictability,Google Style specifies the following (nearly) deterministic scheme.

Beginning with the prose form of the name:

  1. Convert the phrase to plain ASCII and remove any apostrophes. For example,“Müller’s algorithm” might become “Muellers algorithm”.

  2. Divide this result into words,splitting on spaces and any remaining punctuation (typically hyphens).

    • Recommended: if any word already has a conventional camel-case appearance in common usage,split this into its constituent parts (e.g.,“AdWords” becomes “ad words”). Note that a word such as “iOS” is not really in camel case per se; it defies any convention,so this recommendation does not apply.
  3. Now lowercase everything (including acronyms),then uppercase only the first character of:

    • … each word,to yield upper camel case,or
    • … each word except the first,to yield lower camel case
  4. Finally,join all the words into a single identifier.

他们的方案产生IosCompatProxy作为类名,并产生iosCompatProxy作为变量名.他们故意不理会原始大写字母,而是采用基于规则的骆驼案形式.

也许这不是最漂亮的表格,但是如果您正在寻找可以遵循的规则,并且在您工作的地方没有规则,那么Google的风格指南将是您的最佳选择,因为它专门提到“ iOS”.我倾向于高度重视他们的约定,因为他们使用它们维护着大量Java(截至2018 [1]为止有3亿行).

原文链接:https://www.f2er.com/java/532833.html

猜你在找的Java相关文章