Upgrade to Pro — share decks privately, control downloads, hide ads and more …

KotlinとPragmatism / Pragmatism in Kotlin

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
Avatar for jsoizo jsoizo
September 08, 2026

KotlinとPragmatism / Pragmatism in Kotlin

Avatar for jsoizo

jsoizo

September 08, 2026

More Decks by jsoizo

Other Decks in Programming

Transcript

  1. 2011年のブログから With Kotlin, we’re building upon the many years of

    experience creating development tools for different languages, and hoping to provide a language which is productive enough for today’s environment and at the same time simple enough for every programmer to learn. One thing to note: since we’re a development tools company, we’re building firstclass IDE support for Kotlin in parallel with the language itself. ―― Hello World - The JetBrains Blog 7
  2. 2011年のブログから First and foremost, it’s about our own productivity. Although

    we’ve developed support for several JVM-targeted programming languages, we are still writing all of our IntelliJ-based IDEs almost entirely in Java. The IntelliJ build system is based on Groovy and Gant, some Groovy is also used for tests, there is some JRuby code in RubyMine, and that’s it. We want to become more productive by switching to a more expressive language. At the same time, we cannot accept compromises in terms of either Java interoperability (the new language is going to be introduced gradually, and needs to interoperate smoothly with the existing code base) or compilation speed (our code base takes long enough to compile with javac, and we cannot afford making it any slower). ―― Why JetBrains needs Kotlin - The JetBrains Blog 8
  3. 2011年のインタビュー記事から 当時 Twitterが採用するなど 勢いのあったScalaを明確に意識していた “We’ve looked at all of the

    existing JVM languages, and none of them meet our needs. Scala has the right features, but its most obvious deficiency is very slow compilation,” said Dmitry Jemerov, JetBrains development lead, on Friday. JetBrains wants the object-oriented Kotlin language to be safer than Java, statically checking for pitfalls such as null pointer dereference, and more concise than Java. Another goal is to make it simpler than its “most mature competitor,” Scala. ―― JetBrains readies JVM language Kotlin - InfoWorld 9
  4. Androidの制約に面して And Kotlin would have been a whole lot easier

    to design and develop if not for the Java interop, Maven integration, and Android compatibility! It would definitely be more elegant in many ways. But elegance, though highly appreciated, is not the primary goal here – the primary goal is being useful. And the less our users have to relearn, reinvent, redo from scratch, and the more they can reuse, the better. ―― Kotlin 1.0 Released: Pragmatic Language for the JVM and Android - The JetBrains Blog 2010年台前半のAndroid APIはJava 6,7相当。Lambdaもdefaultもない。 KotlinではJava 6バイトコードのままそれらを言語側で埋めた。 && 1.0.2でメソッド数が64Kを超えないよう削減も行われた。 10
  5. 例: Platform Type Kotlinの仕様上、Java由来の型をすべて T? として扱うこともできた。 が、Java APIを利用するたびにnullチェックが必要でコードが冗長になる。 Javaコードの仕様を把握していて、 null

    が返らないと判断できるなら String として受け取れる。 一方で、 null の可能性を排除できないなら String? として受け取ればよ い。 Javaとの境界を実装する人に、安全性と認知負荷のトレードオフを選択でき る余地 を残している。 14
  6. 例: コレクション型のヒエラルキー Scala(2.13以降)の場合 — java.util とは独立した型階層 scala.collection (2.13以降) IterableOnce +-

    Iterable +- Seq +- Set +- Map java.util ✕ 実装関係なし Collection +- List +- Set Map ( ) 独立 import scala.jdk.CollectionConverters._ javaApi.process(xs.asJava) // コピーではなくラッパーを1枚かぶせる 不変性を型で保証できる。代わりに境界では変換が要る。 15
  7. 例: コレクション型のヒエラルキー Kotlin(1.0)の場合 — 宣言はKotlin、実体は java.util kotlin.collections (コンパイル時) Collection +-

    List / MutableList +- Set / MutableSet Map / MutableMap javaApi.process(xs) // java.util (実行時) = Mapped types Collection +- List +- Set Map ( ) 独立 変換なし。java.util.List そのものが渡る シグネチャはどちらも java.util.List 。 16
  8. Kotlinのアプローチ • List は read-only であって immutable ではない ◦ 変更メソッドが見えないだけ。実体が

    ArrayList のこともある • Javaから見れば java.util.List — read-onlyでも add が見える ◦ map の結果は ArrayList 。Javaから add が通る 不変性を型で保証することより、Javaの資産の再利用を優先した。 不変性が重要ならば kotlinx-collections-immutable を使えば良い。 17
  9. 15年経ってのPragmatism KMPの時代となり、Kotlinが動く環境はJVMやAndroidだけではなくなった。 境界がJavaからその他のプラットフォームにも広がっただけ。 We are going another way: providing a

    common language for all platforms while enabling creation of common libraries through seamless interoperability with platform code. ―― Kotlin/Native Tech Preview: Kotlin without a VM - The JetBrains Blog allows developers to share code across platforms while retaining the benefits of native programming ―― Kotlin Multiplatform Is Stable and Production-Ready - The JetBrains Blog 18
  10. Pragmatismは境界に現れる part2 境界 = Pure Kotlinな部分とそうじゃない部分 が増えている • expect/actual —

    共通コードとプラットフォーム実装の切り替え点 • cinterop / external宣言 — KotlinからプラットフォームAPIを呼ぶ • Swift export — プラットフォーム側からKotlinを呼ぶ 19
  11. expect/actualにみるPragmatism KMPがサポートするプラットフォームにはエコシステムが出来上がっている • Apple → Foundation / UIKit / Swift・Objective-C

    libraries • Linux → C / POSIX libraries • Web → JavaScript ecosystem これらを無視して、Kotlinのために同等のAPIやライブラリを ゼロから作り直すのは現実的ではない。 expectで共通宣言、actualで各プラットフォームのライブラリに委譲する ことで、既存のエコシステムを活かしながら共通化をはかる。 20
  12. 見守っていきたい 1. Language Server Protocol • IDE/エディタやエージェントと言語解析エンジン間の標準化 2. Agent Client

    Protocol • コーディングエージェントとIDE/エディタ間の標準化 3. Kotlin Toolchain • 軽量でagent friendly(?)なプロジェクト管理 23
  13. まとめ Pragmatism = 実務で生産的に仕事を進められることを優先する • Javaとの相互運用、ツールチェーン、コンパイル時間など 「現場で使えるか」を美しさより優先して設計された • そのスタンスはJavaとの境界に現れる (Platform

    Type, collection)。 デフォルトは相互運用に有利に、厳密さは境界の実装者に委ねる • 現在でもかわらない。境界はJavaからプラットフォーム全体に広がり、 Agentic Coding時代には開発体験の主語が人からエージェントに移る 24