"VPNAPIs" class 的正确命名是什么
What is the right naming for "VPNAPIs" class
class"VPNAPIs"名字的正确写法是什么?是 VpnApis
、VPNAPIs
还是 VpnAPIs
?
VPN:虚拟专用网络。
API: 应用程序接口。
VpnApis
正确。
根据java的命名约定,
All the classes, interfaces should start with uppercase letter and be
a noun/adjective
Every Java class name must start by Capital Letter meanwhile if
sub-word appear then it's also start by Capital.
答案是所有三种选择都是合法的1,具体取决于您遵循的编码标准以及您选择如何解释它。
我的建议:
- 与您的同事交谈。
- 选择一个风格指南,然后同意您需要遵守的严格程度。
- 运用你的常识。风格指南的目的是最大限度地提高可读性。它们本身并不是目的。
原始 1997 太阳 Java Code Conventions(不再“维护”)。
"Class names should be nouns, in mixed case with the first letter of each internal word capitalized. Try to keep your class names simple and descriptive. Use whole words - avoid acronyms and abbreviations (unless the abbreviation is much more widely used than the long form, such as URL or HTML)."
重要提示:
- 上面并没有说只是内部单词的第一个单词应该大写。
- 虽然它通常建议不要使用缩写词,但它并不强制要求缩写词 应该 的书写方式。
因此:
VpnApis
符合
VPNAPIs
符合(呃!)
VpnAPIs
符合
在 Java SE class 库中使用首字母缩略词的 class 名称的各种示例加强了这种解释。其中许多是在 1997 年之后添加的,这与它们是“历史例外”的说法不符。 (请注意,1997 年是 JDK 1.1 发布的时间!)
"Beginning with the prose form of the name:
- Convert the phrase to plain ASCII and remove any apostrophes. For example, "Müller's algorithm" might become "Muellers algorithm".
- 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.
- 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
- Finally, join all the words into a single identifier."
这给出:
VpnApis
正确,
VPNAPIs
不正确
VpnAPIs
不正确
文档中的示例对此进行了强化。
但是请注意,这些规则显然会指出许多 Java SE class 名称不正确。
1 - 对于什么是值得的,我的偏好是 1) 选择一个不同的 class 名称(这个名称没有明确表明 classes 的目的.. . 尽管如果有更多的上下文可能会),2)使用 VpnApis
,3)使用 VpnAPIs
.
class"VPNAPIs"名字的正确写法是什么?是 VpnApis
、VPNAPIs
还是 VpnAPIs
?
VPN:虚拟专用网络。
API: 应用程序接口。
VpnApis
正确。
根据java的命名约定,
All the classes, interfaces should start with uppercase letter and be a noun/adjective
Every Java class name must start by Capital Letter meanwhile if sub-word appear then it's also start by Capital.
答案是所有三种选择都是合法的1,具体取决于您遵循的编码标准以及您选择如何解释它。
我的建议:
- 与您的同事交谈。
- 选择一个风格指南,然后同意您需要遵守的严格程度。
- 运用你的常识。风格指南的目的是最大限度地提高可读性。它们本身并不是目的。
原始 1997 太阳 Java Code Conventions(不再“维护”)。
"Class names should be nouns, in mixed case with the first letter of each internal word capitalized. Try to keep your class names simple and descriptive. Use whole words - avoid acronyms and abbreviations (unless the abbreviation is much more widely used than the long form, such as URL or HTML)."
重要提示:
- 上面并没有说只是内部单词的第一个单词应该大写。
- 虽然它通常建议不要使用缩写词,但它并不强制要求缩写词 应该 的书写方式。
因此:
VpnApis
符合VPNAPIs
符合(呃!)VpnAPIs
符合
在 Java SE class 库中使用首字母缩略词的 class 名称的各种示例加强了这种解释。其中许多是在 1997 年之后添加的,这与它们是“历史例外”的说法不符。 (请注意,1997 年是 JDK 1.1 发布的时间!)
"Beginning with the prose form of the name:
- Convert the phrase to plain ASCII and remove any apostrophes. For example, "Müller's algorithm" might become "Muellers algorithm".
- 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.
- 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
- Finally, join all the words into a single identifier."
这给出:
VpnApis
正确,VPNAPIs
不正确VpnAPIs
不正确
文档中的示例对此进行了强化。
但是请注意,这些规则显然会指出许多 Java SE class 名称不正确。
1 - 对于什么是值得的,我的偏好是 1) 选择一个不同的 class 名称(这个名称没有明确表明 classes 的目的.. . 尽管如果有更多的上下文可能会),2)使用 VpnApis
,3)使用 VpnAPIs
.