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
100 lines or die
Search
mattak
January 15, 2016
Programming
2.7k
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
100 lines or die
KotlinAndroid勉強会 LT
mattak
January 15, 2016
More Decks by mattak
See All by mattak
人間はどこまでさぼれるか? AIコーディングで人の関与を計測してみた
mattak
0
11
最近やった作業環境改善施策10個
mattak
0
310
UnixTime is Simple
mattak
0
270
おっさんが停滞しないために
mattak
32
19k
tech invest
mattak
1
370
Nodux - node base redux framework
mattak
0
1.6k
what_is_technical_investment
mattak
0
190
unitypackage distribution
mattak
0
890
Unity energy usage
mattak
0
990
Other Decks in Programming
See All in Programming
The Bowling Game- From Imperative to Functional Programming - Part 1
philipschwarz
PRO
0
310
Snowflake Summitでの新機能 CoCo / CoWork / snowflake-summit-2026-overall-what-new-coco
tatsuhiro
1
220
SREは、MCPとSRE Agentをこう使え!
kazumax55
0
150
例外の正しい扱い方 そのエラー try-catchして大丈夫?
jinwatanabe
0
360
OS アップデート対応の取り組み方がもっと共有されてほしい
andpad
0
110
Generative UI & AI-Assistants for Your Angular Solutions
manfredsteyer
PRO
1
160
Hunting Vulnerabilities in Symfony with LLMs
vinceamstoutz
0
580
AI駆動開発を妨げる技術的負債の解消アプローチ / ai-refactoring-approach
minodriven
17
8.9k
地域 SRE コミュニティ最前線 - ホンマでっかSRE勉強会
tk3fftk
0
220
symfony/aiとlaravel/boost
77web
0
120
初めてのKubernetes 本番運用でハマった話
oku053
0
120
ローカルLLMでどこまでコードが書けるか -拡張版 / How much code can be written on a local LLM Extended
kishida
12
4.7k
Featured
See All Featured
Google's AI Overviews - The New Search
badams
0
1.1k
It's Worth the Effort
3n
188
29k
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
1
310
Optimising Largest Contentful Paint
csswizardry
37
3.8k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
2.9k
Build The Right Thing And Hit Your Dates
maggiecrowley
39
3.3k
Building the Perfect Custom Keyboard
takai
2
810
The Anti-SEO Checklist Checklist. Pubcon Cyber Week
ryanjones
0
180
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
21
1.5k
Building Applications with DynamoDB
mza
96
7.1k
Abbi's Birthday
coloredviolet
3
8.6k
Exploring anti-patterns in Rails
aemeredith
3
440
Transcript
(less than) 100 lines or die. "OESPJEͰ,PUMJOษڧձ !NBUUBL
とつぜんですが、
Javaで こんなコードありませ んか?
None
͍ͭͷ·ʹ͔͘ͳ͍ͬͯΔߦɻɻɻ
つらい…!!
もし、 10⾏のコードなら?
1ͰΘ͔Δʂ
100⾏のコードなら?
ेඵ͋Ε ཧղͰ͖Δʂ
1000⾏のコードなら?
ͳ͍ͱ ಡΊͳ͍ʂ
1万⾏のコードなら?
もう⾟くて読めない… でも実在します. https://github.com/android/platform_frameworks_base/blob/master/core/java/android/widget/TextView.java#L10190
Մಡੑ (ཧղʹ͔͔Δ࣌ؒ) ߦ ʢ: Πϝʔδਤʣ
Τϯόά͢Δ֬ ߦ ʢ: Πϝʔδਤʣ
ۤ͢Δ࣌ؒ ߦ ʢ: Πϝʔδਤʣ
ΞχϝΛݟΔ࣌ؒ ߦ ʢ: Πϝʔδਤʣ
⻑いコードを メンテナンスしたくな い!!
というわけで
100 lines or die.
95%のソースコードを 100⾏未満にする!
というミッションで アプリを書いてみまし た。
プロジェクト概要
⾔語: ΞʔΩςΫνϟ: 3ΞʔΩςΫνϟϕʔε σʔλόΠϯσΟϯά: RxJava ϥΠϒϥϦ: kotterknife, retrofit, okhttp, …
結果
97% (ϥΠϒϥϦͳͲαϒϓϩδΣΫτͱςετআ͘) 100ߦະຬ 529 files / ߹ܭ: 545 files
31# 133# 108# 88# 65# 39# 26# 18# 14# 7#
5# 4# 4# 1# 0# 0# 0# 1# 0# 0# 0# 0# 0# 0# 0# 0# 1# 0# 20# 40# 60# 80# 100# 120# 140# 0# 10# 20# 30# 40# 50# 60# 70# 80# 90# 100# 110# 120# 130# 140# 150# 160# 170# 180# 190# 200# 210# 220# 230# 240# 250# 260# (16 files / 545 files) 2.9%
MainActivityɺࠓͷͱ͜Ζ99ߦ
ผϓϩδΣΫτͷΞϓϦ(Java)ͱൺֱ
0" 5" 10" 15" 20" 25" 0" 30" 60" 90"120"150"180"210"240"270"300"330"360"390"420"450"480"510"540"570"600"630"660"690"720"750"780"810"840"870"900"930"960"990"
(39 files / 131 files) 29.7%
※ࣾൺ 10ഒͷՄಡੑ্Λ࣮ݱʂ (͖ͯͱ͏Ͱ͢)
Swift൛ͷΞϓϦͱൺֱ (΄΅ࣅͨΑ͏ͳΞʔΩςΫνϟͰͭͬͨ͘)
1" 49" 44" 33" 23" 20"20" 17"17" 11" 8" 8"
10" 2" 3" 4" 3" 4" 5" 5" 0" 2" 0" 1" 0" 2" 0" 1" 1" 2" 1" 0" 0" 1" 0" 1" 1" 0" 0" 0" 0" 0" 0" 0" 1" 0" 0" 0" 0" 0" 0" 0" 1" 0" 10" 20" 30" 40" 50" 60" 0" 20" 40" 60" 80" 100" 120" 140" 160" 180" 200" 220" 240" 260" 280" 300" 320" 340" 360" 380" 400" 420" 440" 460" 480" 500" 520" (67 files / 307 files) 21.8%
Kotlin͍͢͝ʂ (࣮ࡍʹViewControllerͷ͕͞ओͳࠩ)
短く書く⼯夫 (࣌ؒ͋Ε)
ϓϩδΣΫτͷίʔυશମΛ ͖ͬ͢Γग़དྷͨཁҼΛ͍͔ͭ͘
3層アーキテクチャ ベース
http://www.slideshare.net/mokemokechicken/iosandroidmodel ࢀߟ: iOS/AndroidΞϓϦΤϯδχΞ͕ཧղ͖͢ʮModelʯͷৼΔ͍
"DUJWJUZ $VTUPN 7JFX 'SBHNFOU 7JFX .PEFM .PEFM 4FSWJDF Presentation Layer
Business Layer 20͘Β͍ 100͘Β͍ 100͘Β͍ 100͘Β͍ 10͘Β͍
ΘΓͱׂ͚Ͱ͖͍ͯΔͷͰɺ ංେԽ͢ΔϘτϧωοΫfileগͳ͍
CustomViewの活⽤
Activity, Fragment, CustomView ͷ͍͚ - ϚονϣͳActivityʹ͞ΑͳΒ͢Δํ๏ - http://www.slideshare.net/yanzm/droid-kaigi2015-yanzm
Activity << Fragment << CustomView ϑΝΠϧ
খ͞ͳύʔπ(CustomView)Λ ࢁͭ͘Γ͍ճ͢ํ
<?xml version="1.0" encoding="utf-8"?> <me.mattak.sampleapp.CustomView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <TextView
android:id="@+id/text" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </me.mattak.sampleapp.CustomView> CustomViewͰxmlΛΉ (ύʔπখ͘͞খ͚)
class CustomView : FrameLayout { val textView: TextView by bindView(R.id.text)
constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {} constructor(context: Context, attrs: AttributeSet, defStyle: Int) : super(context, attrs, defStyle) {} override fun onFinishInflate() { super.onFinishInflate() if (this.isInEditMode) { return } // model͔Βσʔλऔಘ val data = Observable.just("text") // observable<String>ͷ༰͕TextViewʹө͞ΕΔ TextViewModel(this.textView, data).subscribe() } } CustomViewͰσʔλόΠϯυ
⼩さな ViewModel構想
None
ImageViewModel TextViewModel AudioButtonViewModel NextPageViewModel
ViewModelͰ͍Ζ͍ΖΓա͗ͳ͍ 1ͭͷViewModelͰ1ͭͷ͜ͱΛΔ
Extensionの活⽤
// File: ScoreEntity.kt data class ScoreEntity( val param1: Int, val
param2: Int ) αʔόʔͱ௨৴͢Δࡍͷ Entityใࣗಈੜ͞ΕΔ
// File: ScoreEntityExtension.kt val ScoreEntity.score: Int get() = param1
* param2 Entityʹਵ͢Δͪΐͬͱͨ͠ϩδοΫ Extensionͱͯ͠ผϑΝΠϧʹॻ͘
ͪΐͬͱͨ͠ϩδοΫ͕ γϣʔτΧοτͰ͖͖ͯͬ͢Γʂ
まとめ
まとめ KotlinͰίʔυΛͬͱ͘ ϝϯς͘͢͠͠Α͏ʂ
Thank you!