我该如何命名我的Java 9模块? [英] How should I name my Java 9 module?

查看:124
本文介绍了我该如何命名我的Java 9模块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个带 groupId = org.abc artifactId = myLibrary 的库。模块名称的推荐名称是什么: myLibrary org.abc.myLibrary ?是否有任何命名方案的官方指南?

Suppose I have a library with groupId = org.abc and artifactId = myLibrary. What is the recommended name for the module name: myLibrary or org.abc.myLibrary? Is there any official guide for a naming scheme?

推荐答案

有一段时间对你的问题有两种不同的意见,但在开发过程中在模块系统中,社区采用反向DNS方法。

For a while there were two different opinions on your question but during the development of the module system, the community settled on the reverse DNS approach.

这里假设模块名称应该是全局唯一的。鉴于这一目标,最实用的方法是遵循包命名策略并反转维护者所关联的域名。 模块系统状态说明了这一点

Here, the assumption is that module names should be globally unique. Given that goal, the most pragmatic way to get there follows the package naming strategy and reverse a domain name the maintainers are associated with. The State of the Module System says this:


模块名称(如包名称)不得冲突。命名模块的推荐方法是使用长期推荐用于命名包的反向域名模式。

Module names, like package names, must not conflict. The recommended way to name a module is to use the reverse-domain-name pattern that has long been recommended for naming packages.

此外,Mark Reinhold 撰写

Furthermore, Mark Reinhold writes:


强烈建议根据反向Internet域名约定命名所有模块。模块的名称应该与其主要导出的API包的名称相对应,该API包也应遵循该约定。如果模块没有这样的包,或者由于遗留原因,它必须具有与其导出的包之一不对应的名称,那么它的名称至少应该以作者的反向形式开头。是关联的。

Strongly recommend that all modules be named according to the reverse Internet domain-name convention. A module's name should correspond to the name of its principal exported API package, which should also follow that convention. If a module does not have such a package, or if for legacy reasons it must have a name that does not correspond to one of its exported packages, then its name should at least start with the reversed form of an Internet domain with which the author is associated.

这很清楚,并由其他Java专家共享喜欢Stephen Colebourne

This is pretty clear and shared by other Java experts like Stephen Colebourne.

有一段时间(2016年初)还有另一个建议进行轮次。 JDK团队表示模块名称可能不一定是唯一的因为模块比定义它们的工件更抽象。 Mark Reinhold写道:

For a while (beginning of 2016) there was another recommendation making the rounds. The JDK team stated that module names may not have to be unique after all "because modules are more abstract than the artifacts that define them". Mark Reinhold writes:


选择以项目或产品名称开头的模块名称。以反向域名开头的模块(和包)名称不太可能发生冲突但是它们不必要地冗长,它们从最不重要的信息开始(例如, com org net ),在外源性变更(如开源捐赠或企业捐赠)后,它们无法正常阅读收购(例如, com.sun。* )。

Choose module names that start with the name of your project or product. Module (and package) names that start with reversed domain names are less likely to conflict but they're unnecessarily verbose, they start with the least-important information (e.g., com, org, or net), and they don't read well after exogenous changes such as open-source donations or corporate acquisitions (e.g., com.sun.*).

反向域名方法在早期是明智的Java的日子,在我们拥有足够复杂的开发工具来帮助我们处理偶尔的冲突之前。我们现在有这样的工具,因此,从项目或产品名称开始的短模块和包名称的优越可读性优于那些以反向域名开头的繁琐冗长。

The reversed domain-name approach was sensible in the early days of Java, before we had development tools sophisticated enough to help us deal with the occasional conflict. We have such tools now, so going forward the superior readability of short module and package names that start with project or product names is preferable to the onerous verbosity of those that start with reversed domain names.

此外,拥有不包含域的模块名称将允许将该模块与另一个实现交换,只要它具有相同的名称(并且当然实现相同的公共API) 。

Also, having module names that do not include a domain would allow exchanging that module against another implementation as long as it has the same name (and implements the same public API of course).

在上面的邮件中,Reinhold记录了他的意见变更:

In the mail lined above, Reinhold documents his change of opinion:


有些人可能更喜欢较短的,面向项目的名称,而这些名称可以在有限的项目中使用,这些项目永远不会在单个组织之外看到光明。但是,如果您创建的模块在将来很少有机会开源,那么最安全的方法是在开始时为它选择反向DNS名称。

Some people may prefer shorter, project-oriented names, and those can be fine to use in limited projects that will never, ever see the light of day outside of a single organization. If you create a module that has even a small chance of being open-sourced in the future, however, then the safest course is to choose a reverse-DNS name for it at the start.



摘要



陪审团参与其中,所有公开发表意见的人都同意反向DNS,就像包裹一样。

Summary

The jury is in and everybody who made his or her opinion public agrees on reverse DNS like for packages.

这篇关于我该如何命名我的Java 9模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆