ϘʔΠεΧτϧʔϧ
Try to leave this world a little better than you found it...
— Robert Baden-Powell
Robert C. Martin ͕ιϑτΣΞ։ൃʹద༻1
ίʔυʹมߋΛՃ͑Δͱ͖ɺվળΛࢪ͢
1 97 Things Every Programmer Should Know: Collective Wisdom from the Experts, Kevlin Henney, 2010
ಋೖͱݪଇ > ݪଇ > ϘʔΠεΧτϧʔϧ
KISS
Keep It Simple Stupid
— Clarence Leonard "Kelly" Johnson
୯७ͳํ๏ΛબͿ
- ՄೳͳݶΓඪ४ͷ࣮Λ͏
- ϥΠϒϥϦɾϑϨʔϜϫʔΫɾσβΠϯͷ༻్ΛߜΔ
ඒ͍͠ɾ༏խͳίʔυ͕ಡΈ͍͢ͱݶΒͳ͍
ಋೖͱݪଇ > ݪଇ > KISS
୯Ұϝιου == ୯Ұʁ
ϝιουͷͰଌΕͳ͍
class Alviss {
// May show a text, may break the device, may launch a rocket,
// may ...
fun doEverything(state: UniverseState)
}
ಋೖͱݪଇ > ݪଇ > ୯Ұݪଇ
Slide 36
Slide 36 text
୯Ұݪଇ
A class should have only one reason to change.
— Robert C. Martin
̎ͭҎ্ͷػೳΛ͍͚ࠞͥͯͳ͍
ಋೖͱݪଇ > ݪଇ > ୯Ұݪଇ
୯Ұݪଇ: Α͘ͳ͍ྫ 2/2
class LibraryBookRentalData(
val bookIds: MutableList,
val bookNames: MutableList,
val bookIdToRenterNameMap: MutableMap,
val bookIdToDueDateMap: MutableMap, ...
) {
fun findRenterName(bookName: String): String?
fun findDueDate(bookName: String): Date?
...
ಋೖͱݪଇ > ݪଇ > ୯Ұݪଇ
୯Ұݪଇ: վળҊ 2/2
data class BookData(val id: Int, val name: String, ...)
data class UserData(val name: String, ...)
class CirculationRecord(
val onLoanBookEntries: MutableMap
) {
data class Entry(val renter: UserData, val dueDate: Date)
ಋೖͱݪଇ > ݪଇ > ୯Ұݪଇ
࣌ظঘૣͳ࠷దԽॾѱͷࠜݯ 1/2
We should forget about small efficiencies,
say about 97% of the time:
premature optimization is the root of all evil.
— Structured Programming with go to Statements, Donald Knuth
ಋೖͱݪଇ > ݪଇ > ࣌ظঘૣͳ࠷దԽॾѱͷࠜݯ
Α͍࠷దԽͷྫ
࠷దԽલ:
val data = arrayList.find { data -> data.key == expectedKey }
࠷దԽޙ:
val data = hashMap[expectedKey]
ίʔυΛ୯७ʹͭͭ͠ ܭࢉྔΛݮΒ͢
ಋೖͱݪଇ > ݪଇ > ࣌ظঘૣͳ࠷దԽॾѱͷࠜݯ
Slide 47
Slide 47 text
ίʔυΛෳࡶʹ͢Δ࠷దԽ 1/2
Yet we should not pass up our opportunities in that critical 3%
— Donald Knuth
ಋೖͱݪଇ > ݪଇ > ࣌ظঘૣͳ࠷దԽॾѱͷࠜݯ