Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I'm currently working on a couple projects in Flash ActionScript, and I've been building up a small library of classes. I've been using a naming convention similar to:

foo.events.Bar and foo.controls.Baz, but I've noticed that many people have released their libraries in the com and org package/namespace (i.e. com.foo.events.Bar and com.foo.controls.Baz). I assume the meaning of com is common or community, and that org is organization.

Is there a particular reason to adding an additional namespace?

Is this common for namespaced languages (Java, C#, AS3,...)?

share|improve this question
    
This convention (com..., org...) seems more popular with Java, I don't seem to recall seeing it as much with C++ or C#. –  FrustratedWithFormsDesigner Apr 7 '11 at 17:34

3 Answers 3

up vote 2 down vote accepted

com doesn't mean common or community, it means commerical, same as in the web. This is important, as the meaning defines the conventions, if you wish to follow them.

As the naming specifications that @Dean referred to say, packages are a hierarchical naming pattern, which means that the most general distinction comes first.

For that, you should follow convention, which is:

  • If you are building commercial software use com (.yourcompanyname).
  • If you are building free/open source software, use org (.yourorganizationname).

As a side note, I remember reading somewhere, though I can't find the source, that Tim Berners-Lee (creator of the URL) said, if he were to create the specification over again, he would put the TLD (.com, .org etc.) first (mirroring software package conventions), as it is the highest level of the hierarchy.

share|improve this answer
    
I'd read that bit TLD + Tim Berners-Lee before as well. I didn't realize it was to mirror software package conventions (or I'd forgotten :-D). –  zzzzBov Apr 7 '11 at 17:39
1  
@zzzzBov - I don't know if it is to mirror them, or if he simply believes that to be the right way, and that software packages got it right. –  NickC Apr 7 '11 at 17:54
    
either way it would have made more sense with increased specificity the farther right you go. It would simplify many issues with sub-domains, as you could easily pattern-match the root com.foo.bar/baz vs bar.foo.com/baz –  zzzzBov Apr 7 '11 at 18:14

The first place I ever saw that naming convention was Java, where is was encouraged that you prefix your package names with your backwards domain name. So if you own "www.foo.com" then you would name your packages "com.foo.whatever" (leave off the "www").

This avoids the possibility of package name conflicts (for example if company "foo" in Australia releases a package, it would be "au.com.foo.whatever").

I've seen it used in other languages as well (python springs to mind) but I believe they just borrowed it from Java.

share|improve this answer

Should is an interesting term, but in any case the concept behind name-spaces is to avoid clashing.

In the days of C and other languages like it :-) , you had functions. If two libraries provided the same function name, you could be out of luck at either compile or link time.

Library one:

/* code dealing with gui */
int draw(void*);

Library two:

/* code dealing with printer */
int draw(void*);

So we started to get in the habit of adding a little company/library based prefix

Library Other one:

/* code dealing with GUI */
int GUI_draw(void*);

Library Other two:

/* other print code */
int PRINT_draw(void*);

And this helped quite a bit, more typing, but since you were less likely to use two of the same library in the same application, it did pretty well.

Languages evolved and the concept became more refined to be a first class concept of namespaces.

Java (citation needed) may have been the first to (widely) adopt the reversed domain name as a namespace. By the very nature of the DNS system, this ensured that there would be no clashing of same names.

So back to should; if you are coding for your personal use, then likely don't bother worrying about it.

If you are coding for a company, consider using their name in the standard reverse order. If the code does not go anywhere else (i.e. is not released open-source), it will not make much of a difference, but it will be least surprise item for future developers who come along and expect that standard convention.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.