天天看點

一些命名規範/some code naming conventions

一些自己平時在寫代碼總會遇到的問題, 在這裡記錄一下,說不定有别人也用到呢?

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

    這個其實裝的是不同的東西, 看似不符合我們上面的規律,但是如果了解為

    [email protected]

    保持保持商标的完整就能了解.

另外一個簡單的規則是:

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

轉載于:https://my.oschina.net/acnt/blog/3014698