1

Is it just me, or is the TLD in the Java package naming convention pretty extraneous? I mean, if you -did- have namespace collision between com.example.package and org.example.package, without the TLD, then with the TLD you have confusion anyway. Why trade-off confusion for namespace collision? Surely the compiler spitting out an error/warning is better than it prancing merrily along trying to compile a program someone imported the wrong package for?

Just my two cents on the convention. Frankly you're not really going to have namespace collision between org. and com. anyway as it's pretty unlikely two identically-named java packages are going to be written by two companies with the same domain but different tlds.

Chris Browne
  • 1,582
  • 3
  • 15
  • 33

7 Answers7

1

It isn't that the com. or org. is significant to the package name, just that "use your company's domain name" is a nice, simple rule of thumb.

Isaac Truett
  • 8,734
  • 1
  • 29
  • 48
  • Sure, it's nice and simple on a superficial level, but I still think `com.example.package` vs `org.example.package` is liable to produce confusion in the unlikely event such a conflict occurs. The fact that it's unlikely alone makes the TLD extraneous, but the confusion caused by the conflict is even more reason to remove it. – Chris Browne Mar 04 '11 at 22:30
1

Sometimes it may be important, but mostly it's more about prestige than actual engineering reasons. It could be compared to the signature of the painter in the corner of the painting, something that says "I made this.", something that makes you notable whenever you're voicing your concerns and/or opinions.

As an example of this, when Apache Software Foundation resigned from JCP, everyone knew the immediate impact of this on their work since all the external 3rd party libraries they use contained the domain: People with lots of org.apache.* imports knew that they should really open an ear for the announcement and start following it closely since it WILL impact them eventually.

Likewise, you can use your company's good reputation to advertise the library; If i were to advertise you a set of collection libraries from some random party, which one would sound better, the one that's under common.collect or the one that's under com.google.common.collect?

Adding the domain part to packages has little to nothing to do with actual practises, it's about taking responsibility and being proud of what you are and what you do. It's about being open, it's about sharing, it's about being part of the community, it's about being you among the 13 million or so of all the software developers across the globe.

Esko
  • 29,022
  • 11
  • 55
  • 82
  • 2
    The key is why the com? Would `google.common.collect` really be any less reputable? – corsiKa Mar 04 '11 at 21:18
  • @glowcoder: Think more generically, there might be major differences between TLD:s which may mislead one completely. Reading one example like a devil's advocate will never do you any good. – Esko Mar 04 '11 at 21:48
  • @glowcoder exactly. And as I pointed out in the OP, `com.google.common.collect` and `org.google.common.collect` being competing libraries with different namespaces (but similar namespace names) is likely to confuse developers. – Chris Browne Mar 04 '11 at 21:58
0

I just ignore it when coding software, but the TLD does help to make the package unique.

Chris Dennett
  • 22,412
  • 8
  • 58
  • 84
0

Like you said, it's just a convention. It's not designed to be perfect; domains can change hands and this would cause collisions as well.

Matthew
  • 44,826
  • 10
  • 98
  • 87
0

If your packages are not libraries (or they are libraries in your own company only) then they are never going to get out and therefore you do not have to follow any package protocol. In fact on standalone apps I just use a single short package name and stick everything inside of it. That simplifies diffing or checksumming commonly used files from separate programs if they use the same package declaration. Here is a question I posted on that: Generic Java Package Name

Community
  • 1
  • 1
700 Software
  • 85,281
  • 83
  • 234
  • 341
0

No.

Proof: There exists another very popular language, with a lot of libraries, all under simple namespaces. And they don't have a problem with name clashing.

irreputable
  • 44,725
  • 9
  • 65
  • 93
0

I asked a question about package names, and Jon Skeet (whoever that guy is) had a good comment to say

from: Hyphenated company name in Java packages

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.

Community
  • 1
  • 1
corsiKa
  • 81,495
  • 25
  • 153
  • 204
  • A valid point raised - the fact that this convention affects the directories as well as the import declarations (something I had overlooked in my original post). When faced with a directory full of packages and I have to first choose com/ or org/, if I don't implicitly know which TLD the package uses, how am I supposed to find it? Granted, this doesn't affect the developer much as it's mostly handled by tools, but I'm sure the situation will crop up eventually... – Chris Browne Mar 04 '11 at 22:33