Java 包中带连字符的公司名称
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3678520/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Hyphenated company name in Java packages
提问by corsiKa
Say you're working on the core module of the foo
project for BarBaz Incorporated. Your code fragment might look like this:
假设您正在foo
为 BarBaz Incorporated 开发项目的核心模块。您的代码片段可能如下所示:
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
?
如果您公司的网站不是barbaz.com
,而是 ,那么惯例会是bar-baz.com
什么?
采纳答案by Steve Turner
The SUN-era Java Language Specificationgives a suggested convention:
SUN 时代的Java 语言规范给出了一个建议的约定:
If the domain name contains a hyphen, or any other special character not allowed in an identifier(§3.8), convert it into an underscore.
如果域名包含连字符或标识符中不允许的任何其他特殊字符(第 3.8 节),请将其转换为下划线。
But it's just a suggestion...
但这只是一个建议......
回答by Erick Robertson
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.
只需删除连字符。包名称根本不需要与网站名称匹配。更重要的是公司生产的包之间的一致性,因此它们都使用相同的基本包名称。
回答by Jon Skeet
I would personally just remove the hyphen. You couldchange it into an underscore, but that would look pretty ugly.
我个人会删除连字符。您可以将其更改为下划线,但这看起来很丑陋。
It's highly unlikely it's reallygoing 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?
它不太可能真的与另一家同名但没有连字符的公司发生冲突。即使两家公司都是技术公司,都使用 Java,那么任何人在同一代码库中使用它们创建的代码的可能性有多大?
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.
老实说,我希望 Java 在约定方面没有走这条路。我想知道有多少个名为“com”或“org”的目录与单个成员一起存在 - 一个具有更有意义名称的子目录。
回答by Dave B
I work on lots of government stuff and we typically use the underscore so bar_baz.
我从事很多政府工作,我们通常使用下划线,所以 bar_baz。
回答by Amy B
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.
我只是查看了浏览器的历史记录,在过去的 2 个月里,我没有访问过带连字符的单个域。所以约定是重命名公司。
Alternatively, leave out the hyphen, because BazBaz won't ever include Baz=Baz's code in their own.
或者,省略连字符,因为 BazBaz 永远不会在他们自己的代码中包含 Baz=Baz 的代码。