https://kotlinlang.org logo
Title
s

smichel17

09/02/2021, 3:02 PM
In java,
import foo.bar.Baz
tells me that I can find the
Baz
source code in
…/foo/bar/Baz.java
. However, in Kotlin I might have multiple classes per file, or maybe I'm importing an extension function, it's no longer clear which file I actually have to look in to find the definition. Does this bother anyone else and how do you handle it?
h

hho

09/02/2021, 3:14 PM
It does bother me as well, but I guess that's what you get when a company selling IDEs makes a language…?
I try to stick to the Java convention if possible, even though that sometimes means a one-liner
data class
in a separate file. 🤷‍♂️
That being said, IntelliJ is awesome.
:blob-grin: 1
s

smichel17

09/02/2021, 3:17 PM
I found https://github.com/Kotlin/kotlin-style-guide/issues/6 which suggests using different package statements for files within the same directory.
So I guess I could write packages that include the file name, although the Java interop > "Package name does not match containing directory" inspection complains about this
(I'm not sure if it's a hard rule in java that packages must match the directory structure, or whether that's just a convention?)
c

christophsturm

09/02/2021, 3:38 PM
in java its a hard rule
s

smichel17

09/02/2021, 3:39 PM
Err, I should s/in java/on the jvm/
c

christophsturm

09/02/2021, 3:39 PM
and in kotlin you should match the directory structure, but you can omit empty root packages (flatten the directory structure) unfortunately that will trigger very interesting idea bugs
s

smichel17

09/02/2021, 5:05 PM
Right, but then we're back to the problem of the first message in this thread: then the import doesn't tell you which file it comes from.
c

christophsturm

09/02/2021, 5:45 PM
for me the flatter directory structures that kotlin allows actually improve the experience without ide
s

smichel17

09/02/2021, 5:51 PM
I like flatter directory structures, I just don't like trading one problem for another :(
Is there anything actually wrong with having
…/foo/bar/Baz.kt
with
package foo.bar.baz
?
I guess I should just try it and see if anything breaks :P
I like js modules, where each file is one and that's that.
(If only it had reasonable namespacing…)