In multiplatform projects, I find it quite inconve...
# language-proposals
l
In multiplatform projects, I find it quite inconvenient to have related files split among separate directories where the common parent is multiple levels away. I just got an idea that could resolve this problem: Using the extension to specify the sourceSet the file belongs to. For example, we'd have
Stuff.kt
that'd default to
commonMain
,
Stuff.js.kt
in the
main
directory that'd be part of the
jsMain
sourceSet,
TestWhatever.js.kt
in the
test
directory would be part of the
jsTest
sourceSet, and
Stuff.darwin.kt
in the
main
directory would be part of the custom
darwinMain
sourceSet. That also makes me think about how
.main.kts
,
.gradle.kts
and
.whatever.kts
files all resolve different symbols based on their extension.
e
could probably coerce Gradle to do that, but IIRC IntelliJ gets really unhappy with overlapping sourceset directories
https://kotlinlang.org/docs/coding-conventions.html#directory-structure
In pure Kotlin projects, the recommended directory structure follows the package structure with the common root package omitted.
if you're following that, there shouldn't be that many levels of deep directories anyway
l
I know that all, but this is a proposal.
I'm mostly interested in what people think about the idea, before making IDEA support it is considered.
e
IMO we're fine as it is now, and using extensions is confusing - .main.kts would mean something very different than .main.kt
if anything, I think it would be more useful to have something like Rust's
#[cfg(...)]
, but I'm not sure that's compelling enough either
l
Then… cool for you if you're fine with the status quo, I guess?
e
you asked for opinions, you got mine
s
Hey Louis 👋 Very cool idea! This has already been proposed internally, several times. We’re already had discussions for that. Personally, I am a big fan of this proposal. Unfortunately, there is nothing more to share, other than: “We will have this in mind” 👀
👀 1
l
I guess I should create an issue on YouTrack for that?
u
+1 from my side for this proposal
d
Like the idea too (this is also how Clojure somehow handles it)
l
Looks similar, yes.
e
looks closer to the Rust-like
#[cfg]
I mentioned before. I think that makes more sense than file extensions.