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
6
最近やった作業環境改善施策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
OSもどきOS
arkw
0
560
RTSPクライアントを自作してみた話
simotin13
0
600
Inside Stream API
skrb
1
700
A2UI という光を覗いてみる
satohjohn
1
130
並列実装の現場、2ヶ月間実務でAIを使い倒したAIもPCも私も限界が近い
ming_ayami
0
130
Vite+ Unified Toolchain for the Web
naokihaba
0
290
エンジニアと一緒にテストコードの設計と実装を改善した話
mototakatsu
0
160
運用エージェントは "作る" から "育てる" へ - 記憶と自己進化の3層設計パターン / self-evolving-agents-three-layer-agent-design
gawa
12
3.7k
AIとASP.NET Coreで雑Webアプリを作った話
mayuki
0
560
AIだと陥りがちなJakarta EE最新技術への移行時の落とし穴と解決策
tnagao7
0
110
ユニットテストの先へ:テスト技法で要求・仕様を整理するJava開発実践 / Beyond_Unit_Testing_Practical_Java_Development_Techniques_for_Organizing_Requirements_and_Specifications
shimashima35
0
400
Spring Security 実践 ─ GraphQL APIで実務に役立つ 認証・認可 を学ぶ
wagyu
0
230
Featured
See All Featured
The Curse of the Amulet
leimatthew05
1
13k
Everyday Curiosity
cassininazir
0
230
Crafting Experiences
bethany
1
180
Information Architects: The Missing Link in Design Systems
soysaucechin
0
970
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
210
Visualization
eitanlees
152
17k
Large-scale JavaScript Application Architecture
addyosmani
515
110k
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
2
1.5k
A designer walks into a library…
pauljervisheath
211
24k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
Technical Leadership for Architectural Decision Making
baasie
3
410
Unlocking the hidden potential of vector embeddings in international SEO
frankvandijk
0
840
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!