Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Androidからサーバーサイドまで!プログラミング言語 Kotlinの魅力 #devboost
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Taro Nagasawa
December 15, 2018
Programming
3k
5
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Androidからサーバーサイドまで!プログラミング言語 Kotlinの魅力 #devboost
Developers Boots (
https://event.shoeisha.jp/devboost/20181215
)で発表したスライドです。
Taro Nagasawa
December 15, 2018
More Decks by Taro Nagasawa
See All by Taro Nagasawa
Android開発者のための Kotlin Multiplatform入門
ntaro
0
1.8k
Kotlin 最新動向2022 #tfcon #techfeed
ntaro
1
2.4k
#Ubie 狂気の認知施策と選考設計
ntaro
14
14k
UbieにおけるサーバサイドKotlin活用事例
ntaro
1
1.2k
KotlinでSpring 完全理解ガイド #jsug
ntaro
6
3.7k
Kotlinでサーバサイドを始めよう!
ntaro
1
1.1k
Kotlin Contracts #m3kt
ntaro
4
4.4k
How_to_Test_Server-side_Kotlin.pdf
ntaro
1
580
Kotlin Fest 2018 - Opening session
ntaro
0
4.4k
Other Decks in Programming
See All in Programming
【やさしく解説 設計編・中級 #6】良いアーキテクチャとは ~ 一本の登り道の、行き先 ~
panda728
PRO
0
220
変わらないものが、変わるものを決める — 意図駆動開発 × イベントソーシング × イミュータブル | What Doesn't Change Decides What Can — IDD × Event Sourcing × Immutability
tomohisa
0
1.8k
AI時代のPHPer生存戦略 ~「言語、もうなんでもよくない?」に本気で向き合う~
vivion
0
790
プロポーザルを書いてもらう
pvcresin
0
550
Terraform標準の組織で AWS CDKをどう使うか
mu7889yoon
1
530
メールのエイリアス機能を履き違えない
isshinfunada
0
240
Claude CodeとAgentCore Gatewayを繋ぐ際の認証認可 / Authentication and authorization when connecting Claude Code with AgentCore Gateway
har1101
2
300
5分で問診!Composer セキュリティ健康診断
codmoninc
0
1k
Claude Code全社展開のためにやったことn選~プラグイン302個・コミッター271人を支えるために~
kenchan
5
1.6k
freeeにおけるEvalsの実践例の紹介
freee
PRO
0
120
FDEが実現するAI駆動経営の現在地
gonta
2
290
わからない話を追いかけたら、プログラミング言語を作る側にいた
ydah
3
520
Featured
See All Featured
Principles of Awesome APIs and How to Build Them.
keavy
128
18k
Designing Experiences People Love
moore
143
24k
Utilizing Notion as your number one productivity tool
mfonobong
4
550
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
650
How STYLIGHT went responsive
nonsquared
100
6.2k
[RailsConf 2023] Rails as a piece of cake
palkan
59
6.9k
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
11
990
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
420
Why You Should Never Use an ORM
jnunemaker
PRO
61
10k
Darren the Foodie - Storyboard
khoart
PRO
3
3.6k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1.5k
Transcript
2018-12-13 Developers Boost 長澤太郎 Androidからサーバーサイドまで! プログラミング言語 Kotlin の魅力
長澤 太郎 • @ngsw_taro • Ubie株式会社 ソフトウェアエンジニア • 日本Kotlinユーザグループ代表
「世界中の人々を適切な医療に案内する」
Kotlin
Kotlinとは • JetBrainsにより開発されているプログラミング言語 ◦ IntelliJ IDEAの強力な機能を利用可能 • 静的型付けオブジェクト指向言語 ◦ 言語の種類としてはJavaと同じ
• JVMやAndroidを主要なターゲットとして登場したが、 JavaScriptやNativeも重要なターゲットとしている • 2011年に発表され、安定版が2016年にリリースされた
1. Kotlinのここがスゴイ! 2. KotlinでAndroid開発 3. KotlinでWebアプリ開発
本日紹介する Kotlinのスゴイところ • 読み書きが容易な文法 • 演算子オーバロード • 拡張関数
読み書きが容易な文法: クラスとプロパティ class 分数(val 分子: Int, val 分母: Int) val
half = 分数(1, 2) println(half.分子) // 1と表示される println(half.分母) // 2と表示される
読み書きが容易な文法: 文字列テンプレート class 分数(val 分子: Int, val 分母: Int) {
override fun toString(): String { return "${分子}/${分母}" } } val half = 分数(1, 2) println(half) // 「1/2」と表示される
演算子オーバロード 独自クラスにも演算子を適用可能 class 分数(val 分子: Int, val 分母: Int) {
operator fun plus(that: 分数): 分数 { return 分数( 分子 * that.分母 + that.分子 * 分母, 分母 * that.分母 ) } ...略... val sum = 分数(1, 2) + 分数(1, 3) println(sum) 「5/6」と表示される
拡張関数 既存の型にメソッドを追加しているように見せる operator fun Int.plus(r: 分数): 分数 { return 分数(
this * r.分母 + r.分子, r.分母 ) } val sum = 2 + 分数(1, 5) println(sum) 「11/5」と表示される
1. Kotlinのここがスゴイ! 2. KotlinでAndroid開発 3. KotlinでWebアプリ開発
Android開発におけるKotlinのスゴイところ • Javaとの相互運用性 • @Percelize • コルーチン
Javaとの相互運用性: 例えばSAM変換 button.setOnClickListener(object: OnClickListener { override fun onClick(view: View) {
/* クリック時の処理 */ } }) button.setOnClickListener { /* クリック時の処理 */ }
@Percelize Percelable対応クラスを自動実装してくれる仕組み @Percelize class User( val id: Long, val name:
String ): Percelable • Androidでオブジェクトをシリアライズする仕組み • 仕様に沿った実装を提供する必要があり、冗長になりがち • JavaにはあるがKotlinには存在しない概念が必要 ◦ 回避策はあるがあまりスマートにならない
コルーチン 特にasync/awaitによる非同期処理 // コールバック方式 api.getFoo { foo -> api.getBar(foo) {
bar -> show(bar) } } // コルーチン GlobalScope.launch(Dispatchers.Main) { val foo = async { api.getFoo() }.await() val bar = async { api.getBar(foo) }.await() show(bar) }
1. Kotlinのここがスゴイ! 2. KotlinでAndroid開発 3. KotlinでWebアプリ開発
Webアプリ開発におけるKotlinのスゴイところ • Spring Framework 対応 • Kotlin向けWAF Ktor
Spring Bootプロジェクトの雛形作成 Webサイト または IntelliJ IDEA で 簡単にプロジェクト雛形を作 成可能
アノテーションベースのいつものSpring @SpringBootApplication class DemoApplication fun main(args: Array<String>) { runApplication<DemoApplication>(*args) }
@Service class HelloWorldService { fun helloWorld(): String = "Hello, world!" } @RestController class HelloWorldController(val helloWorldService: HelloWorldService) { @GetMapping("/hello-world") fun helloWorld(): String = helloWorldService.helloWorld() }
KotlinDSLによるDIとルーティング設定も fun main(args: Array<String>) { SpringApplicationBuilder() .sources(DemoApplication::class.java) .initializers(beans { bean
{ HelloWorldService() } bean { HelloWorldController(ref()) } bean { router { GET("/hello-world") { ref<HelloWorldController>().helloWorld() } } } }) .run(*args) } Bean 登録 routing 設定
Kotlin向けWebアプリフレームワーク Ktor • https://github.com/ktorio/ktor • JetBrainsにより開発 • 先日 1.0.0がリリースされた(現在 1.0.1)
• いわゆるマイクロ・フレームワーク • Kotlin DSLによるルーティング設定 • ノンブロッキング、コルーチン対応 fun main(args: Array<String>) { embeddedServer(Netty, 8080) { routing { get("/") { call.respondText("Hello, world!", ContentType.Text.Html) } } }.start(wait = true) }
まとめ • KotlinはJetBrainsに開発されている若い言語 • 書いて楽しい!読んで快適!実践主義な文法 • 相互運用性が高く、既存のJava資産を活かせる • コルーチンにより、簡単なコードで軽量スレッド •
Webアプリケーション用フレームワークも充実