问题
"TLD-first domain-like identifiers" is a mouthful but that's all I can come up with.
I've seen these used in various places over the years and wondered what the history/reason behind this convention is, since you might be forgiven in thinking that there is one true way to mention a domain.
I don't use Java but I recall from poking around that namespaces are often done like this:
uk.co.tophats.stitchkit
A specification file for a "Launch Agent" on Mac OS X:
ws.agile.1PasswordAgent.plist
A preferences file on Mac OS X:
com.apple.iTunesHelper.plist
Why is the TLD first? Is it just hierarchical pedantry like UK vs. US date formats?
回答1:
For the case of Java, the packages correspond directly to directory hierarchy, and it makes far more sense for the directory hierarchy to be rooted at the most general, rather than the most specific, domain identifier. Also, when reading off directory hierarchy, it is most common to read it from the top down. So I'd say the convention of flipping the order of domain components makes sense there.
回答2:
In Java and other programming languages, the package identifier dictates how the directory hierarchy of the project is.
So if you have two packages com.stackoverflow.server
and com.stackoverflow.client
, you'll end up with this directory layout:
com/
stackoverflow/
client/
server/
which is good and logical, while the other way around would give you
client/
stackoverflow/
com/
server/
stackoverflow/
com/
which is impratical.
回答3:
Its a way of using a globally unique name as the prefix to all your namespaces and thus keep all your namespaces private to the globally unique name.
回答4:
In sience, notation is normally started with the most significant bit of information, to make ordering and grouping of the information easier. The TLD is the root of the domain structure and thus the most significant bit of information. So it makes sense to structure the packages this way. Sure, it doesn't matter if it's com.example.mypackage or example.com.mypackage. But SUN decided to prefer the more sientific way.
Regarding the date format, be aware that there is an ISO describing an "interchange format" as: YYYY-MM-DD
It's the same scheme, because the year is the most significant part, followed by the Month and Date.
So, when looking from this point, the one who is using the "wrong" notation is the DNS system itself. But I think they tried to optimize the whole thing for parsing of an url (e.g. The "www" first, to indicate a WebServer)
回答5:
It's a bit subjective. You can be used to conventions like "stackoverflow.com"
, and wonder what the heck all this "com.apple"
stuff is about. Or you can be a programmer with years of experience and stuff like "System.out"
could be the most natural thing for you.
com.apple
is like saying "look into the com
domain, inside this, look for apple
".
apple.com
is like saying "look for apple
, which can be found in the com
domain".
So it all depends on the environment/situation you're using. Just my two cents!
回答6:
No, it's not pedantry, it's to create a namespace.
There might be other 3 party developers/programs/etc. that also could create a iTunesHelper.plist or a SQLRunner.java class. You prefix these with your own namespace, e.g. your domain name to create a reasonably unique name so com.oracle.SQLRunner.java is different and doesn't clash with org.postgresql.SQLRunner.java
来源:https://stackoverflow.com/questions/3651491/whats-the-significance-of-tld-first-domain-like-identifiers