<story><title>Kotlin 1.2 Released: Sharing Code Between Platforms</title><url>https://blog.jetbrains.com/kotlin/2017/11/kotlin-1-2-released/</url></story><parent_chain></parent_chain><comment><author>EddieRingle</author><text>Multiplatform docs here: &lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;kotlinlang.org&amp;#x2F;docs&amp;#x2F;reference&amp;#x2F;multiplatform.html&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;kotlinlang.org&amp;#x2F;docs&amp;#x2F;reference&amp;#x2F;multiplatform.html&lt;/a&gt;&lt;p&gt;Example from the docs:&lt;p&gt;&lt;pre&gt;&lt;code&gt;  &amp;#x2F;&amp;#x2F; Common module
  
  package org.jetbrains.foo
  
  expect class Foo(bar: String) {
      fun frob()
  }
  
  fun main(args: Array&amp;lt;String&amp;gt;) {
      Foo(&amp;quot;Hello&amp;quot;).frob()
  }

  &amp;#x2F;&amp;#x2F; JVM module
  
  package org.jetbrains.foo
  
  actual class Foo actual constructor(val bar: String) {
      actual fun frob() {
          println(&amp;quot;Frobbing the $bar&amp;quot;)
      }
  }
&lt;/code&gt;&lt;/pre&gt;
I brought up how I thought the `expect` and `actual` keywords (but primarily the latter) added unneeded verbosity in the Kotlin Slack awhile back and was pretty much shrugged off, despite folks on the Kotlin team admitting that they exist in part to make the IDE&amp;#x27;s job easier, but weren&amp;#x27;t actually necessary.&lt;p&gt;It leaves a sour taste in my mouth, but I suppose it might be because I&amp;#x27;m familiar with projects in C&amp;#x2F;C++ where, if a symbol goes undefined, the compiler&amp;#x2F;linker is smart enough to tell you that without being hand-held.</text></comment>
<story><title>Kotlin 1.2 Released: Sharing Code Between Platforms</title><url>https://blog.jetbrains.com/kotlin/2017/11/kotlin-1-2-released/</url></story><parent_chain></parent_chain><comment><author>jdonaldson</author><text>I really like some of Kotlin&amp;#x27;s decisions, but I prefer Haxe&amp;#x27;s approach to this.&lt;p&gt;For single target code, you can prefix the class module with the platform tag (e.g. &amp;quot;js&amp;quot; or &amp;quot;java&amp;quot;).  These module names are reserved within the compiler and any code therein is restricted to their respective targets.&lt;p&gt;Another way is to use conditional compilation markers to indicate specific target-compatible boundaries.  E.g.&lt;p&gt;&lt;pre&gt;&lt;code&gt;  #if java
     public function print(s : String) java.lang.System.out.println(v);
  #end
&lt;/code&gt;&lt;/pre&gt;
That method only exists on the java target, and the compiler will complain otherwise.&lt;p&gt;Conditional compilation also allows for more fine-grained support of multiple targets:&lt;p&gt;&lt;pre&gt;&lt;code&gt;  #if java
     public function print(s : String) java.lang.System.out.println(v);
  #elseif js
     public function print(s : String) console.log(v);  &amp;#x2F;&amp;#x2F; as a simple example
  #end
&lt;/code&gt;&lt;/pre&gt;
This makes a cleaner organizational distinction between &lt;i&gt;extern code&lt;/i&gt; that must remain target specific, and true &lt;i&gt;cross platform&lt;/i&gt; code that can be called on any of the supported targets.  Editors can pick up on this very easily and provide early warnings as you are typing, and doc generators can also inspect these directives and show api availability between targets in the rendered docs.&lt;p&gt;(self-disclosure: Haxe compiler contributor)</text></comment>