Is there any convention for package names ? Should...
# getting-started
t
Is there any convention for package names ? Should we stick to Java conventions (for example
reverse.domain.name.myapp.mymodule
), or is it possible to use shorter names such as
myapp.mymodule
?
n
two things to consider: 1. Kotlin doesn't force you to match the package name to the actual path of the file, buut...IMO they should be consistent. if it's
com.company.foo
, it should be in
com/company/foo/
directory. (though as I said, doesn't have to be) 2. Kotlin's
internal
is moderately different from package private, which if anything means you can create more packages internally without making everything be public. as for your actual question...I'd still namespace it by domain.
f
that said I think we fall into the good practices of if you're not coding for java, it's still ok to be nice and be compatible with it in case someone else wants your code.
a
Istr the JB convention is to remove the trailing empty directories from the source paths (so if a top-level class is com.example.thing.Main that’s in src/main/kotlin/Main.kt and com.example.thing.util.Utils would be in src/main/kotlin/util/Utils.kt)
I have memories of encountering Scala classes at work called “util.Error” … of course, multiple conflicting versions of this made its way into internal libraries eventually