没有自己的域的项目的 Java 包命名空间
对于如何为没有自己的域的开源项目命名包命名空间,是否有通用的经验法则?
命名空间应该是唯一的,因此选择域来解决这个问题,但最终这并不重要,只要它们是唯一的即可。
现在,如果我有一个仅托管在 github 上的项目,是否可以接受
com.github.username.projectname
,或者因为我使用的域名并非我真正拥有的而令人不悦?
Is there a general rule-of-thumb on how to name package namespaces for open source projects with no own domain?
Namespaces should be unique, so domains were chosen to take care of that, but in the end it doesn't matter, as long as they are unique.
Now, if I have a project that is only hosted on github, is it okay to take
com.github.username.projectname
or is that rather frowned upon, because I use a domain that I don't really own?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
有许多 com.google.code 和项目的包名称中都带有 sourceforge,因此命名空间有很多先例。
There are a number of com.google.code and projects with sourceforge in the package name, so that namespacing has plenty of precedent.
在您的示例中,
com.github
与您的代码没有直接关系。此代码的存储位置(也称为托管)并不重要,并且将来可能会发生变化。因此,我建议使用一个纯粹的项目特定名称,例如或 ,
因为包名称不需要是域名。
哦,顺便说一句:您会发现几乎所有有关命名约定的优先级 - 不仅仅是 Java 包名称。但从根本上来说:在历史上,你也可以找到每种谋杀的先例。这是否仅仅因为其他人以前做过,就在某种程度上使它可以接受?我不这么认为。
In your example
com.github
has no direct relationship to your code. Where this code is stored (aka. hosted) does not matter and might change in the future. Therefore I propose a purely project specific name likeor even
since a package name does not need to be a domain name.
Oh, by the way: You will find precedence for nearly all and everything regarding naming conventions - not only for Java package names. But drastically speaking: In the history you can find precedence for every kind of murder also. Does that somehow make it acceptable only because someone else had done it before? I don't think so.
没关系。一般来说,只需选择“可能”独特且特定于项目的东西即可。
通常,只有当包是为使用而设计的库时,包才会发生冲突。如果这些包仅在项目内部使用,那就没那么重要了。
It's fine. In general, just pick something "likely" to be unique, and project-specific.
Packages generally only collide when they're a library designed for consumption; if the packages are for use inside the project only, it matters much less.