1

Being new to Grails, Groovy, and even Java, I was wondering why many Grails developers use the naming convention such as

com.{projectName}.{className}

What is the point of organizing them first by the com (what does it even mean?), and then project name (when it's already within the project folder)?

2 Answers 2

6

More of a Java standard. See http://docs.oracle.com/javase/tutorial/java/package/namingpkgs.html

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.

3
  • Interesting. But why organize in such way? If companies have different sites under different domains, wouldn't it be better to just have separate environments to avoid any confusion?
    – jjj
    Dec 18, 2012 at 0:23
  • 2
    In the end it comes down to individual requirements. Does this convention work for you? Great. Otherwise, do you're own thing.
    – Mike Park
    Dec 18, 2012 at 0:29
  • 1
    Putting everything in the default package is ok when the app is tiny, but often apps get quite large and refactoring into a logical structure can be a huge hassle. It's best to use proper standards from the beginning. Dec 18, 2012 at 0:53
0

In Java, the intention is to have code play nicely when it may have different authors in different companies. For example, I write an application that has the notion of a User and I assign it to the default package. I need to make use of your framework/library and it too has the notion of a User assigned to the default package. Which User should be loaded and when should it be used? By packaging based on a company's reversed domain name, we can organise User objects based on each company's definition and use, and our code can co-exist.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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