Java 包中连字符的公司名称
假设您正在为 BarBaz Incorporated 开发 foo
项目的核心模块。您的代码片段可能如下所示:
package com.barbaz.foo.core;
import com.barbaz.foo.util;
如果您公司的网站不是 barbaz.com
,而是 bar-baz.com
,那么惯例是什么?
Say you're working on the core module of the foo
project for BarBaz Incorporated. Your code fragment might look like this:
package com.barbaz.foo.core;
import com.barbaz.foo.util;
What would the convention be if your company's website was not barbaz.com
, but instead bar-baz.com
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
SUN 时代 Java 语言规范给出了建议的约定:
但这只是一个建议...
The SUN-era Java Language Specification gives a suggested convention:
But it's just a suggestion...
我刚刚查看了浏览器的历史记录,在过去 2 个月中我没有访问过带有连字符的单个域。所以惯例是给公司更名。
或者,省略连字符,因为 BazBaz 永远不会在自己的代码中包含 Baz=Baz 的代码。
I just looked through my browser's history, and in the last 2 months I haven't visited a single domain with a hyphen. So the convention is to rename the company.
Alternatively, leave out the hyphen, because BazBaz won't ever include Baz=Baz's code in their own.
我个人会删除连字符。您可以将其更改为下划线,但这看起来非常难看。
它不太可能真的与另一家同名但去掉连字符的公司发生冲突。即使两家公司都是科技公司,都使用 Java,但任何人在同一代码库中使用它们创建的代码的可能性有多大?
说实话,我希望 Java 在约定方面没有走这条路。我想知道有多少个名为“com”或“org”的目录包含一个成员 - 一个具有更有意义名称的子目录。
I would personally just remove the hyphen. You could change it into an underscore, but that would look pretty ugly.
It's highly unlikely it's really going to clash with another company with the same name minus the hyphens. Even if both companies are tech companies, both using Java, what are the chances that anyone's going to be using code created by both of them in the same codebase?
To be honest, I wish that Java hadn't gone down this path in terms of conventions. I wonder how many directories called "com" or "org" exist with a single member - a subdirectory with a more meaningful name.
只需删除连字符即可。包名称根本不需要与网站名称匹配。更重要的是,公司生产的软件包之间具有一致性,因此它们都使用相同的基本软件包名称。
Just drop the hyphen. The package name doesn't need to match the website name at all. It is more important that there's consistency among packages produced by the company so they all use the same base package name.
我从事很多政府工作,我们通常使用下划线,所以 bar_baz。
I work on lots of government stuff and we typically use the underscore so bar_baz.