Hyphenated company name in Java packages

JavaNaming ConventionsPackage

Java Problem Overview


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?

Java Solutions


Solution 1 - Java

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...

Solution 2 - Java

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.

Solution 3 - Java

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.

Solution 4 - Java

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.

Solution 5 - Java

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestioncorsiKaView Question on Stackoverflow
Solution 1 - JavaSteve TurnerView Answer on Stackoverflow
Solution 2 - JavaAmy BView Answer on Stackoverflow
Solution 3 - JavaJon SkeetView Answer on Stackoverflow
Solution 4 - JavaErick RobertsonView Answer on Stackoverflow
Solution 5 - JavaDave BView Answer on Stackoverflow