<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: romaa.dev</title>
    <description>The latest articles on DEV Community by romaa.dev (@romaa_dev).</description>
    <link>https://dev.to/romaa_dev</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2805879%2F1366da72-a401-4547-9a61-93150f7b9e93.png</url>
      <title>DEV Community: romaa.dev</title>
      <link>https://dev.to/romaa_dev</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/romaa_dev"/>
    <language>en</language>
    <item>
      <title>From expected to actual: Kotlin doesn't reinvent, it reuses 🔄</title>
      <dc:creator>romaa.dev</dc:creator>
      <pubDate>Thu, 26 Jun 2025 23:57:41 +0000</pubDate>
      <link>https://dev.to/romaa_dev/from-expected-to-actual-kotlin-doesnt-reinvent-it-reuses-304j</link>
      <guid>https://dev.to/romaa_dev/from-expected-to-actual-kotlin-doesnt-reinvent-it-reuses-304j</guid>
      <description>&lt;p&gt;A few days ago, I decided to dive into Kotlin. The reason? &lt;strong&gt;Work.&lt;/strong&gt;&lt;br&gt;
I knew Kotlin was based on Java, but to be honest, I don’t have much experience with Java. I haven’t used it in years, and even back then, I never really went deep into it. In recent years, my main focus has been Python.&lt;/p&gt;

&lt;p&gt;I started playing with Kotlin by solving a few Leetcode problems and, being the curious dev I am, I wanted to check which methods &lt;code&gt;IntArray&lt;/code&gt; had. I was working with that data type and expected to find a list of available functions directly in its definition, just like I’d do in Python with &lt;code&gt;dir()&lt;/code&gt; or by checking a class’s documentation.&lt;/p&gt;

&lt;p&gt;But that’s when things got interesting.&lt;/p&gt;

&lt;p&gt;I opened the official Kotlin docs and noticed that methods like &lt;code&gt;sort()&lt;/code&gt; weren’t defined directly inside the &lt;code&gt;IntArray&lt;/code&gt; class. That felt odd.&lt;/p&gt;

&lt;p&gt;After a bit more digging, I landed on &lt;a href="https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/sort.html" rel="noopener noreferrer"&gt;the documentation for the &lt;code&gt;sort()&lt;/code&gt; function&lt;/a&gt; and found this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="n"&gt;expect&lt;/span&gt; &lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nc"&gt;IntArray&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="nc"&gt;Unit&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And I thought:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;expect? What on earth is that?&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I also noticed that in the different platform tabs (JS, Native, Wasm-JS, Wasm-WASI), it showed up as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="n"&gt;actual&lt;/span&gt; &lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nc"&gt;IntArray&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But in the JVM tab, &lt;strong&gt;it didn’t&lt;/strong&gt;. Instead, I found this generic version:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;T&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;out&lt;/span&gt; &lt;span class="nc"&gt;T&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;.&lt;/span&gt;&lt;span class="nf"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;More confused than ever, I headed over to the Kotlin GitHub repository for some clarity. That’s when things started to make sense: I noticed folders like &lt;code&gt;common&lt;/code&gt;, &lt;code&gt;jvm&lt;/code&gt;, &lt;code&gt;js&lt;/code&gt;, &lt;code&gt;native&lt;/code&gt;, &lt;code&gt;wasm&lt;/code&gt;, etc.&lt;br&gt;
And then I remembered — &lt;strong&gt;Kotlin is a multiplatform language.&lt;/strong&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  🧩 expect and actual: the multiplatform system
&lt;/h2&gt;

&lt;p&gt;Digging deeper, I discovered Kotlin’s &lt;code&gt;expect&lt;/code&gt; / &lt;code&gt;actual&lt;/code&gt; system. The idea is simple, but really powerful:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;expect&lt;/code&gt; declares a function, class, or behavior that should exist on all platforms.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;actual&lt;/code&gt; provides the platform-specific implementation (JVM, JS, Native, etc.).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And here’s the part that blew my mind:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;✨ &lt;strong&gt;Kotlin doesn't reinvent — it delegates&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;For example, the implementation of &lt;code&gt;IntArray.sort()&lt;/code&gt; for the JVM platform is as simple as this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="n"&gt;actual&lt;/span&gt; &lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nc"&gt;IntArray&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="nc"&gt;Unit&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;size&lt;/span&gt; &lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;java&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;util&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Arrays&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;💥 Boom! Kotlin didn’t write its own sorting algorithm from scratch. It just reused what was already in the JVM (Java).&lt;/p&gt;

&lt;p&gt;And that makes total sense: &lt;strong&gt;Why reinvent the wheel when Java has spent years optimizing those functions?&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What I learned from all this
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Kotlin is multiplatform, but &lt;strong&gt;by default it runs on the JVM.&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Many basic classes, functions, and primitives like &lt;code&gt;Int&lt;/code&gt;, &lt;code&gt;List&lt;/code&gt;, &lt;code&gt;Array&lt;/code&gt;, &lt;code&gt;String&lt;/code&gt;, etc., &lt;strong&gt;are delegated to Java.&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;The folders &lt;code&gt;common&lt;/code&gt;, &lt;code&gt;jvm&lt;/code&gt;, &lt;code&gt;js&lt;/code&gt;, etc., in the Kotlin repo show how a shared API gets implemented differently per platform.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;expect&lt;/code&gt; defines what should exist, &lt;code&gt;actual&lt;/code&gt; provides the implementation per target.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So, if you’re working with Kotlin and you run into an expect, and you're not explicitly using Kotlin Multiplatform, that &lt;strong&gt;implementation most likely comes straight from Java.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Final thoughts
&lt;/h2&gt;

&lt;p&gt;Kotlin doesn’t reinvent the wheel. It reuses it, builds on top of it… and speeds up 🚗💨&lt;/p&gt;

&lt;p&gt;As someone coming from Python, seeing this kind of design decision in a modern language felt incredibly elegant.&lt;/p&gt;

&lt;p&gt;This was a great welcome into the Kotlin ecosystem.&lt;br&gt;
And I’m just getting started.&lt;/p&gt;

&lt;p&gt;Thanks for reading — hope you found this useful! Keep coding. 🖖&lt;br&gt;
Thoughts? Let me know! 💬&lt;/p&gt;




&lt;p&gt;✍️ Este post también está disponible en espñol - ¡&lt;a href="https://romaadev.medium.com/del-expected-al-actual-kotlin-no-reinventa-reutiliza-46cd4f94ccef" rel="noopener noreferrer"&gt;dale un vistazo aquí&lt;/a&gt;! 🇪🇸&lt;/p&gt;

</description>
      <category>kotlin</category>
      <category>programming</category>
      <category>software</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
