I’m more familiar with Rust’s module system. In Kotlin, I’m sometimes tempted to create a package that contains a single file, with a few top-level declarations. But that results in a directory containing a single file. Is this bad practice? What are the alternatives? A file with a bunch of public declarations? A file with a top-level class to contain the declarations?
h
hfhbd
12/23/2023, 10:56 AM
What do you really want, a namespace? Kotlin does not have namespace but packages. A single file in a package is absolutely okay, but it is just a name. Kotlin does not have package-private visibility and you can always add an import so I would not overuse packages but have bigger packages, to have better auto complete/visibility.
The name of the actual classes/functions is more important than the package name.
t
Tim Chirananthavat
12/23/2023, 10:58 AM
Soooo... just put it into a file (along side others in a higher-level package) and don't worry about it being visible outside?
Tim Chirananthavat
12/23/2023, 10:58 AM
I find the lack of package-private visibility extremely odd.
h
hfhbd
12/23/2023, 10:59 AM
If you worry, make it internal, only visible in the module.
👍 1
h
hho
12/29/2023, 6:52 PM
If you want a package-private modifier, you should vote for KT-29227 – it's currently the third-highest voted open issue on the Kotlin issue tracker...