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
3
最近やった作業環境改善施策10個
mattak
0
300
UnixTime is Simple
mattak
0
260
おっさんが停滞しないために
mattak
32
18k
tech invest
mattak
1
370
Nodux - node base redux framework
mattak
0
1.6k
what_is_technical_investment
mattak
0
180
unitypackage distribution
mattak
0
890
Unity energy usage
mattak
0
980
Other Decks in Programming
See All in Programming
3Dシーンの圧縮
fadis
1
690
軽量Java基盤の設計 DIコンテナに頼らない、長期保守と1秒起動の実現 JJUG CCC 2026 Spring
macha64
0
490
AIとASP.NET Coreで雑Webアプリを作った話
mayuki
0
490
Oxlintのカスタムルールの現況
syumai
6
1.1k
LLM Plugin for Node-REDの利用方法と開発について
404background
0
170
Datadog × OpenTelemetry 入門と実践のあいだ
kn_to_maxpno
1
150
Lessons from Spec-Driven Development
simas
PRO
0
150
A2UI という光を覗いてみる
satohjohn
1
120
The NotImplementedError Problem in Ruby
koic
1
670
Make SRE Operations Easier with Azure SRE Agent
kkamegawa
0
5.2k
Spec-Driven Development with AI-Agents: From High-Level Requirements to Working Software
antonarhipov
2
480
Vite+ Unified Toolchain for the Web
naokihaba
0
230
Featured
See All Featured
RailsConf 2023
tenderlove
30
1.5k
Kristin Tynski - Automating Marketing Tasks With AI
techseoconnect
PRO
0
270
What's in a price? How to price your products and services
michaelherold
247
13k
Side Projects
sachag
455
43k
Believing is Seeing
oripsolob
1
140
Balancing Empowerment & Direction
lara
6
1.2k
How to Think Like a Performance Engineer
csswizardry
28
2.6k
JAMstack: Web Apps at Ludicrous Speed - All Things Open 2022
reverentgeek
1
470
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
Highjacked: Video Game Concept Design
rkendrick25
PRO
1
380
GitHub's CSS Performance
jonrohan
1033
470k
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
62
44k
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!