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.8k
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
15
最近やった作業環境改善施策10個
mattak
0
320
UnixTime is Simple
mattak
0
280
おっさんが停滞しないために
mattak
32
19k
tech invest
mattak
1
380
Nodux - node base redux framework
mattak
0
1.6k
what_is_technical_investment
mattak
0
200
unitypackage distribution
mattak
0
900
Unity energy usage
mattak
0
1k
Other Decks in Programming
See All in Programming
実装をデザインガイドラインに追従させるための取り組み / 260731-dip-mosh-design-system
dachi023
0
8k
関東Kaggler会_NVIDIA_Nemotron_コンペ_振り返り
rick_ds
0
770
T3DD26: From RAGs to Riches
martinhelmich
0
130
How I Won Prize Money at a Hackathon Using Codex and Symphony Alpha
yasei_no_otoko
0
130
30年振りにコンパイラの定数整数除算を改善した
herumi
9
4.4k
プロポーザルを書いてもらう
pvcresin
0
590
Press start. Python's next generation.
willingc
PRO
3
290
[PyCon KR 2026] More Variants, More Diversity for AI Accelerators
achimnol
0
130
go-spidermonkeyでAIエージェントのCode Modeを実装する
syumai
3
1.4k
わからない話を追いかけたら、プログラミング言語を作る側にいた
ydah
3
580
コンパウンドプロダクト開発のためのローカルプロセスマネージャー再発明 #layerxgo
izumin5210
0
600
DroidKaigi 2026 「個人開発という実験場: Android エンジニアが手にする4つの自由」
slashnephy
0
120
Featured
See All Featured
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
1
290
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
11k
Claude Code どこまでも/ Claude Code Everywhere
nwiizo
67
57k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
49
10k
The Mindset for Success: Future Career Progression
greggifford
PRO
0
480
Amusing Abliteration
ianozsvald
1
280
DBのスキルで生き残る技術 - AI時代におけるテーブル設計の勘所
soudai
PRO
68
57k
Skip the Path - Find Your Career Trail
mkilby
1
210
How to Talk to Developers About Accessibility
jct
2
530
HDC tutorial
michielstock
2
830
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
390
Agile that works and the tools we love
rasmusluckow
331
22k
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!