一些自己平时在写代码总会遇到的问题, 在这里记录一下,说不定有别人也用到呢?
java包名用单数还是复数? package names be singular or plural?
这个问题比较典型, 每次创建包名的时候都会遇到, 比如组件 用wedgit
还是wedgit?
是view
or views
. 今天给这个问题测地解决了:
Use the plural for packages with homogeneous contents and the singular for packages with heterogeneous contents.
翻译: 对于同性质的内容用复数包名, 不同类型的内容用单数.
举例
java.util
这个包是工具类, 里面装的是很多不同种类的工具类.android.widget
这个里装的是很多的widget
, 各色各样的都有.- ...
反例
java.beans
这个其实装的是不同的东西, 看似不符合我们上面的规律,但是如果理解为JavaBean@TM
保持保持商标的完整就能理解.
另外一个简单的规则是:
singular when the classes in the package are classification and plural when they are implementations.
翻译: 声明用单数, 实现用复数
git的分支名称用驼峰?下划线? What are some examples of commonly used practices for naming git branches?
首先第一点, 按照最佳实践来 有时候还是有一些困惑, 比如有个踢猫
的分支我到底用feature/KickCat
?kick_cat
, 还是Kick_Cat
feature/Kick/Cat
这个小问题可以通过随便选取一个来搞定, 但是总是挺别扭的! 那就看看别的代码是怎么来搞的.
When you need to use space, use dash" is a strange way to say that you must not use a space. Because it is more common for the command line descriptions to use dashed-multi-words, you do not even want to use spaces in these places. // https://github.com/git/git/commit/e703d7118c68bb5b1f850dae4060609a88500b18 git的代码仓库里面的一个cmt.
//翻译: 如果你需要空白的时候, 用分隔号.
示例
- Android 源码的分支名称
- eclair-sholes-release2
- froyo-release
- kitkat-mr1.1-release
tag的命名规范有
Tagging Specification (SemVerTag) This sub-specification SHOULD be used if you use a version control system (Git, Mercurial, SVN, etc) to store your code. Using this system allows automated tools to inspect your package and determine SemVer compliance and released versions.
- When tagging releases in a version control system, the tag for a version MUST be "vX.Y.Z" e.g. "v3.1.0".
参考链接
Tag的命名规范: https://stackoverflow.com/a/2011372 包名单数, 复数的讨论@SO: https://softwareengineering.stackexchange.com/questions/75919/should-package-names-be-singular-or-plural
包名单数, 复数的讨论@REDDIT: https://www.reddit.com/r/java/comments/1e4ug8/should_package_name_be_plural_or_singular/