Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Androidからサーバーサイドまで!プログラミング言語 Kotlinの魅力 #devboost
Search
Taro Nagasawa
December 15, 2018
Programming
3.1k
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
590
Kotlin Fest 2018 - Opening session
ntaro
0
4.4k
Other Decks in Programming
See All in Programming
マイコン向けの軽量Ruby「PicoRuby」で各種デバイスを制御するネイティブアプリの実現手法
bash0c7
0
330
The Good Stuff, Not the Slop: Engineering High-Quality Android Apps with Modern AI Tooling
danybony
1
240
Webの地図
yosuke_furukawa
PRO
6
4.1k
LLMは4年分のCompose移行を再現できるのか?実プロダクト279件のXMLで探る自動化の境界線
makun
0
550
個人開発基盤をまるごとCloudflareに引っ越して爆速で総合的体験を向上させた話
tinykitten
0
160
XP祭りでしか伝わらないフリップネタ #xpjug
murabayashi
0
140
巨大モノリシックアプリ モダン化大作戦
ktcryomm
0
850
フロントエンドUIフレームワークのこれまでとこれから
ssssota
5
2.4k
AIとGame Jamで、ゲームを完成させた話
takahirosaeki
0
120
Can LLMs Replicate 4 Years of Compose Migration? Exploring the boundaries of automation with 279 XML files from a real product
makun
0
130
Deep dive into the select statement (GopherCon UK)
jespino
0
170
20260914 AIエージェント時代のPlatform Engineering LLM基盤とプロダクトの責務境界線
kanfab1
4
1.3k
Featured
See All Featured
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
240
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.9k
Design of three-dimensional binary manipulators for pick-and-place task avoiding obstacles (IECON2024)
konakalab
0
590
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
128
56k
Art, The Web, and Tiny UX
lynnandtonic
304
22k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.8k
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
3k
Embracing the Ebb and Flow
colly
88
5.2k
RailsConf 2023
tenderlove
30
1.5k
Introduction to Domain-Driven Design and Collaborative software design
baasie
1
980
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.6k
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アプリケーション用フレームワークも充実