Java 包中连字符的公司名称

发布于 2024-09-18 14:46:34 字数 239 浏览 4 评论 0原文

假设您正在为 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

我三岁 2024-09-25 14:46:34

SUN 时代 Java 语言规范给出了建议的约定:

如果域名包含连字符或 标识符 (§3.8),将其转换为下划线。

但这只是一个建议...

The SUN-era Java Language Specification gives a suggested convention:

If the domain name contains a hyphen, or any other special character not allowed in an identifier (§3.8), convert it into an underscore.

But it's just a suggestion...

拿命拼未来 2024-09-25 14:46:34

我刚刚查看了浏览器的历史记录,在过去 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.

冰魂雪魄 2024-09-25 14:46:34

我个人会删除连字符。您可以将其更改为下划线,但这看起来非常难看。

它不太可能真的与另一家同名但去掉连字符的公司发生冲突。即使两家公司都是科技公司,都使用 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.

尘世孤行 2024-09-25 14:46:34

只需删除连字符即可。包名称根本不需要与网站名称匹配。更重要的是,公司生产的软件包之间具有一致性,因此它们都使用相同的基本软件包名称。

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.

余厌 2024-09-25 14:46:34

我从事很多政府工作,我们通常使用下划线,所以 bar_baz。

I work on lots of government stuff and we typically use the underscore so bar_baz.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文