Hyphenated company name in Java packages

40,008

Solution 1

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

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

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

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

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

Share:
40,008
corsiKa
Author by

corsiKa

I'm here to find out about the mysteries of air.

Updated on August 28, 2020

Comments

  • corsiKa
    corsiKa over 3 years

    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?

  • Bill K
    Bill K over 13 years
    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.
  • corsiKa
    corsiKa over 13 years
    I think the board of directors will take issue with this approach, but I LOL'd as well!
  • Erick Robertson
    Erick Robertson over 13 years
    If barbaz.com and bar-baz.com were both producing libraries, one of them would be suing the other.
  • corsiKa
    corsiKa over 13 years
    That's interesting, considering how most Java suggestions recommend against the use of underscores in most identifiers.
  • root
    root almost 11 years
    Apparently, only the person who asked the question can accept an answer. Unfortunately...
  • corsiKa
    corsiKa over 10 years
    So I ran into this the other day again (I'm actually not at the same place anymore) and I stumbled across an Oracle tutorial with a handy chart at the bottom. According to the way back machine, it's been around since late 2011, a year after this question. The recommendations at the bottom sure do make me wonder!
  • Jon Skeet
    Jon Skeet over 10 years
    @corsiKa: Ick. Looks horribly ugly to me! I can't remember the last time I saw an underscore in a package name, to be honest...
  • corsiKa
    corsiKa over 10 years
    Upon further consideration, I had to give the checkbox to Steve's suggestion. Check out the links in my comment on Jon Skeet's answer for why.
  • Erick Robertson
    Erick Robertson over 10 years
    I cannot complain about that.
  • ŁukaszBachman
    ŁukaszBachman over 8 years
    "...rename the company" - not very helpful.
  • ameenhere
    ameenhere about 7 years
    LOL. Leading to another stackoverflow question "what is the eclipse shortcut key to rename my company. ALT+Shift+R is not working"
  • Bassinator
    Bassinator almost 6 years
    I work at a company that has a | character in it's official legal entity name. Literal hell.
  • nsandersen
    nsandersen over 5 years
    My high school still has it in their domain name after more than 20 years. The irony is that its full name does not have the hyphen!
  • tgkprog
    tgkprog over 3 years
    My packages just have the main domain name sel2in.translate ... or s2n.translate i mean unless there is a company called s2n who also do what i do...leave out the com
  • atom88
    atom88 about 3 years
    According to this, it's a REQUIREMENT, not a suggestion (JSR)? Isn't that correct? blog.eisele.net/2010/09/hyphen-ussage-in-package-names.html