What's the significance of TLD-first domain-like identifiers?

空扰寡人 提交于 2019-12-01 22:22:07

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.

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.

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.

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)

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!

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!