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
12
最近やった作業環境改善施策10個
mattak
0
310
UnixTime is Simple
mattak
0
270
おっさんが停滞しないために
mattak
32
19k
tech invest
mattak
1
380
Nodux - node base redux framework
mattak
0
1.6k
what_is_technical_investment
mattak
0
190
unitypackage distribution
mattak
0
900
Unity energy usage
mattak
0
990
Other Decks in Programming
See All in Programming
型も通る、synthも通る、それでも危ない 〜AIのCDKの権限とコストを機械で検証する〜 / It Passes Type Checks, It Passes Synth Checks, but It’s Still Risky — Automatically Verifying Permissions and Costs in AI’s CDK —
seike460
PRO
1
510
信頼性について考えてみる(SRE NEXT 2026 miniLT)
hayama17
0
230
<title><a id="</title>君はこのHTMLをパースできるか"></a></title> #雑LT_study
pizzacat83
0
130
ビデオ通話が繋がる0.2秒で何が起きているのか
supurazako
2
160
人間の目はかわらない、だからJPEGは30年もつ
yuzneri
12
17k
自動化したのに回らないテスト運用の壁ーAI時代の品質責任と生産性
mfunaki
0
120
Prismを使った型安全な暗号化_関数型まつり2026
_fhhmm
0
160
霧の中の代数的エフェクト
funnyycat
1
450
AI Engineeringは、AIプロダクトだけのものか? 〜AIがソフトウェアを作る時代の新しい当たり前〜 / No AI in your product. AI Engineering in your development.
rkaga
4
320
PHP に部分適用が来るぞ!……ところで何それ?おいしいの? #phpcon / phpcon-2026
shogogg
0
480
AWS DevOps AgentのAzure接続機能を検証して見えた活用法/Use Cases Verified for the AWS DevOps Agent's Azure Connectivity Feature
masakiokuda
1
190
20260722_microCMSで考える、AI時代のコンテンツ運用設計
yosh1
0
190
Featured
See All Featured
Highjacked: Video Game Concept Design
rkendrick25
PRO
1
420
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
240
How GitHub (no longer) Works
holman
316
150k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
201
75k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.5k
エンジニアに許された特別な時間の終わり
watany
108
250k
Public Speaking Without Barfing On Your Shoes - THAT 2023
reverentgeek
1
470
Gemini Prompt Engineering: Practical Techniques for Tangible AI Outcomes
mfonobong
2
470
Building Applications with DynamoDB
mza
96
7.1k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.5k
B2B Lead Gen: Tactics, Traps & Triumph
marketingsoph
0
190
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!