this post was submitted on 12 Sep 2023
38 points (95.2% liked)

Technology

57473 readers
3609 users here now

This is a most excellent place for technology news and articles.


Our Rules


  1. Follow the lemmy.world rules.
  2. Only tech related content.
  3. Be excellent to each another!
  4. Mod approved content bots can post up to 10 articles per day.
  5. Threads asking for personal tech support may be deleted.
  6. Politics threads may be removed.
  7. No memes allowed as posts, OK to post as comments.
  8. Only approved bots from the list below, to ask if your bot can be added please contact us.
  9. Check for duplicates before posting, duplicates may be removed

Approved Bots


founded 1 year ago
MODERATORS
 

Why are packages labled com.person.mypackage rather than just person.mypackage

all 8 comments
sorted by: hot top controversial new old
[–] [email protected] 48 points 11 months ago (1 children)

They used DNS domains as a namespace to keep one company's work from colliding with another.

https://en.wikipedia.org/wiki/Reverse_domain_name_notation

[–] [email protected] 24 points 11 months ago (1 children)

To expand on this, it’s the naming convention that Java defines.

Package names are written in all lower case to avoid conflict with the names of classes or interfaces.
Companies use their reversed Internet domain name to begin their package names—for example, com.example.mypackage for a package named mypackage created by a programmer at example.com.

https://docs.oracle.com/javase/tutorial/java/package/namingpkgs.html

[–] [email protected] 15 points 11 months ago (1 children)

Further it isn't always com, you'll often see net, org, and rarely even io show up as the base package. All that said with the introduction of modules and some of the other recent changes I'm not sure how much longer we're going to see the reversed DNS naming system stick around.

[–] [email protected] 11 points 11 months ago* (last edited 11 months ago) (1 children)

I’ve quite often seen people shoehorn their Github account into this format. com.github.username.projectname is quite a common sight for Flatpak packages. Reverse DNS naming assumes every package is created by a company while nowadays a large portion of popular packages were created by individuals.

[–] [email protected] 4 points 11 months ago (1 children)

It doesn't check for an actual DNS entry though, right? Would it be possible to do person.developer.app?

[–] [email protected] 13 points 11 months ago

Correct, there's no actual validation done. You can literally make the package anything you want, you don't even need to follow the convention if you don't want to, although it is of course considered best practice to do so. The entire reason it exists is just as a convenient way to namespace Java classes without worrying about collisions. I personally think using com.github.username.projectname is a perfectly fine way to use the system and is completely within the spirit of it. Likewise if you wanted to use person.developer.app you could, although that's a little weirder. You might be better off using something like dev.person.app, although you'd need to be careful you don't accidentally step on someones toes if someone actually has the registration for person.dev.

[–] [email protected] 7 points 11 months ago

I addition to the answers others have given, consider the large centralized package repositories for software development: npm, PyPI, crates.io, etc. If you frequently publish packages to these indexes, you often will find name collisions and are forced to come up with clever names. In the case of PyPI specifically, it is even worse because while your pip package might be uniquely named, the actual importable python package may not be, and you end up where two pip packages clobber each other. Java's system is verbose but it is simple and solved this problem decades ago.