Title
b

benleggiero

03/10/2017, 9:02 PM
If Kotlin for JVM, JS, and Native are to coexist happily, we're gonna need conditional compiler commands like
#if(JS)
v

voddan

03/10/2017, 9:04 PM
Why not create different libraries/modules for different platforms ?
b

benleggiero

03/10/2017, 9:10 PM
Because eventually I'm going to hit a point where I want the same thing on different platforms. Anyone who's built the same app for desktop, mobile, and web knows that 98% of it is identical, and you only really need to adjust for "touch vs mouse" and "large vs small screens". Maybe for "long vs short lifecycle", too, but there's not much else. Why have two entirely separate projects for iOS vs JVM when I could have the exact same one, but abstracted a bit?
The use case that keeps swimming in my head is Java SE's
Graphics2D
and Cocoa Touch's
CGContext
. They're almost identical in API, so I want to write an abstraction layer called
GraphicsContext
that will call branch off to one or the other depending on the OS you compiled it for
v

voddan

03/10/2017, 9:25 PM
Maybe it could work with a shared interface (in pure Kotlin) and two implementations in two different modules for two targets
šŸ‘ 3
It would not even require more code than
#if
Actually even less
b

benleggiero

03/10/2017, 9:26 PM
Alright, what about `typealias`es?
v

voddan

03/10/2017, 9:27 PM
What about them?
b

benleggiero

03/10/2017, 9:27 PM
What if, for Kotlin Native, I want to do what Cocoa did with
CGFloat
and have a type that's 32-bit on 32-bit platforms, and 64-bit on 64-bit ones? https://github.com/apple/swift/blob/master/stdlib/public/SDK/CoreGraphics/CGFloat.swift.gyb#L26-L35
v

voddan

03/10/2017, 9:36 PM
I have not a slightest idea šŸ˜€
p

pniederw

03/11/2017, 1:45 AM
fwiw, a number of popular scala libraries target both jvm and js
b

benleggiero

03/11/2017, 2:22 AM
It'd be great to see those! I'd love to know how they did it
p

pniederw

03/11/2017, 5:17 AM
afaik, significant parts of the scala language and stdlib are available on both platforms, so foundational libraries (e.g. cats) may get away with a single codebase.
b

bashor

03/13/2017, 6:34 PM
In 1.2 timeframe we going to work on this (https://youtrack.jetbrains.com/issue/KT-6359). Feel free to star or vote the issue to get updates.
šŸ˜„ 1