I'm learning to scala and I'm seeing official document for style guide for scala. But I am confused why same expression is encourage and discourage at the same time.
According to scala style guide first package coolness
is wrong but the second package coolness
which is in middle of example, is right.
// wrong! this is definitely wrong
package coolness
// right! puts only coolness._ in scope
package com.novell.coolness
// right! puts both novell._ and coolness._ in scope
package com.novell
package coolness //but why is it OK?
// right, for package object com.novell.coolness
package com.novell
/**
* Provides classes related to coolness
*/
package object coolness {
}
Solved : I didn't know that package declaration that over 2lines is same as one line declaration separate with dot.
Speaking of,
package com.novell.coolness
is same package com.novell; package coolness
It says right above the code you quoted that package names should follow the Java package naming conventions. The Java package naming conventions state that package names should be globally unique, and that this is achieved by using an Internet domain name that is under the control of the package author as the prefix for the package name.
For example, if you control the domain example.com
, then you can use any package name like com.example._
for your packages, but you can not use, for example, com.microsoft.coolness
.
So, com.novell.coolness
is okay, because it follows the above rule (assuming you are Ray Noorda), but coolness
is not, because it doesn't follow that rule (or, if it were following that rule, then it would imply that you are under the control of the .
root domain namespace, which is almost certainly not true, unless you are ICANN).
This is really not a question about Scala at all, this is a question about Java package naming conventions, which the Scala style guide suggests you follow.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With