views:

115

answers:

5

Let's 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 companies website was not barbaz.com, but instead bar-baz.com?

Thanks in advance!

+4  A: 

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.

Erick Robertson
It is also used to avoid namespace collisions in libraries. If barbaz.com created a product using a library from bar-baz.com (who dropped their hyphen) there would possibly be conflicts. In practice this is so unlikely as to be laughable.
Bill K
If barbaz.com and bar-baz.com were both producing libraries, one of them would be suing the other.
Erick Robertson
+3  A: 

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.

Jon Skeet
A: 

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

Dave B
+6  A: 

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.

Coronatus
Awesome. I LOL'ed.
Erick Robertson
I think the board of directors will take issue with this approach, but I LOL'd as well!
glowcoder
+2  A: 

The Java Language Spec (http://java.sun.com/docs/books/jls/third_edition/html/packages.html#40169) 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...

Steve Turner
That's interesting, considering how most Java suggestions recommend against the use of underscores in most identifiers.
glowcoder