加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

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

发布时间:2020-12-14 19:25:42 所属栏目:Java 来源:网络整理
导读:某些品牌名称实际上并不喜欢使用首字母大写,更改名称可能会使外观看起来完全不同,尤其是对于“ iOS”而言.还有更多类似“ mCore”,“ macOS”等等.关于班级名称,我应该将首字母大写还是保留原样? 例如“ iOSCompatProxy”和“ IOSCompatProxy” 最佳答案 对

某些品牌名称实际上并不喜欢使用首字母大写,更改名称可能会使外观看起来完全不同,尤其是对于“ 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亿行).

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读