ίϝϯτ
ίʔυதʹॻ͔ΕΔऍɾઆ໌
- ௨ৗɺίϯύΠϥΠϯλϓϦλ͔Βແࢹ͞ΕΔ
/**
* Explanation of `fooFunction`...
*/
fun fooFunction(parameter: Parameter /* note of the parameter */) {
barFunction() // Explanation of why `barFunction` is called
/* A comment with
multiple lines. */
ίϝϯτ > ಋೖ
ίϝϯτʹΑΔϦϑΝΫλϦϯά: ྫ
/**
* Adds a new pair of keyword and the definition to this dictionary,
* can be referenced by [getDefinition(String)].
*
* If the keyword is already registered, this registration fails.
* Then, this returns a boolean representing whether the registration
* succeeded.
*/
fun add(newData: Pair): Boolean
ಈ࡞ͷ୯७͞ͷׂʹ͍ίϝϯτ͕ඞཁ
ίϝϯτ > ಋೖ
ίϝϯτʹΑΔϦϑΝΫλϦϯά: ݁Ռ
/**
* Adds or overwrites a definition of a given [keyword].
* The registered definition is obtained by [getDefinition(String)].
*/
fun registerDefinition(keyword: String, definitionText: String)
ಈ࡞ͷ୯७͞ʹݟ߹ͬͨίϝϯτΛॻ͘
ίϝϯτ > ಋೖ
Slide 10
Slide 10 text
දతͳίϝϯτͷछྨ
- υΩϡϝϯςʔγϣϯ: Ϋϥεɾؔʹॻ͘ܗࣜతͳίϝϯτ
/**
* A list of pairs of a string keyword and the explanation text.
*
* ... (details of usage, limitations, etc.)...
*/
class Dictionary {
...
}
ίϝϯτ > ಋೖ
Slide 11
Slide 11 text
දతͳίϝϯτͷछྨ
- υΩϡϝϯςʔγϣϯ: Ϋϥεɾؔʹॻ͘ܗࣜతͳίϝϯτ
- ඇܗࣜతͳίϝϯτ: ίʔυதͷ༷ʑͳॴʹॻ͔ΕΔίϝϯτ
// Call `toList` here to create a copied list explicitly.
val listSnapshot = list.toList()
ίϝϯτ > ಋೖ
Slide 12
Slide 12 text
දతͳίϝϯτͷछྨ
- υΩϡϝϯςʔγϣϯ: Ϋϥεɾؔʹॻ͘ܗࣜతͳίϝϯτ
- ඇܗࣜతͳίϝϯτ: ίʔυதͷ༷ʑͳॴʹॻ͔ΕΔίϝϯτ
- To do ίϝϯτ:
// TODO:
,
// FIXME:
ίϝϯτ > ಋೖ
Ξϯνύλʔϯ: ఆ໊ٛͱಉ͡
/**
* Gets the description for a keyword.
*/
fun getDescription(keyword: String): String
ίϝϯτ > υΩϡϝϯςʔγϣϯ > Ξϯνύλʔϯ
Slide 23
Slide 23 text
Ξϯνύλʔϯ: ίʔυΛ༁͚ͨͩ͠
/**
* Calls [doA] if `conditionA` is satisfied.
* Otherwise, calls [doB] and if ...
*/
fun getDescription(keyword: String): String {
if (conditionA) {
doA()
} else {
doB()
if (...) {...}
}
ίϝϯτ > υΩϡϝϯςʔγϣϯ > Ξϯνύλʔϯ
Slide 24
Slide 24 text
Ξϯνύλʔϯ: ϓϥΠϕʔτϝϯόΛͬͯઆ໌
/**
* Returns a string stored in a private map [dictionary].
*/
fun getDescription(keyword: String): String
ίϝϯτ > υΩϡϝϯςʔγϣϯ > Ξϯνύλʔϯ
Slide 25
Slide 25 text
Ξϯνύλʔϯ: ཁ͕ͳ͍
/**
* Throws an exception if the given `keyword` is empty.
*/
fun getDescription(keyword: String): String
ίϝϯτ > υΩϡϝϯςʔγϣϯ > Ξϯνύλʔϯ
Slide 26
Slide 26 text
Ξϯνύλʔϯ: ݺͼग़͠ଆʹݴٴ
/**
* ...
* This is called by class [UserProfilePresenter].
*/
fun getDescription(keyword: String): String
ίϝϯτ > υΩϡϝϯςʔγϣϯ > Ξϯνύλʔϯ
ཁͷॻ͖ํ: ॏཁͳίʔυ 1/2
ίʔυͰ ࠷ॏཁͳ ߦɾϒϩοΫɾཁૉΛݟ͚ͭΔ
if (!user.isValid) return
val rawProfileImage = getProfileImage(user.id, ...)
val roundProfileImage = applyRoundFilter(rawProfileImage, ...)
profileView.setImage(roundProfileImage)
ίϝϯτ > υΩϡϝϯςʔγϣϯ > ཁ
Slide 32
Slide 32 text
ཁͷॻ͖ํ: ॏཁͳίʔυ 2/2
࠷ॏཁͳΛॻ͖ɺ ิ͢Δ
/**
* Shows a roundly cut profile image of a given [user].
* ...
*/
...
profileView.setImage(roundProfileImage)
ཁ໋໊ͷώϯτʹͳΔ
!
ίϝϯτ > υΩϡϝϯςʔγϣϯ > ཁ
Slide 33
Slide 33 text
ཁͷॻ͖ํ: ίʔυͷڞ௨
ίʔυͷڞ௨Λ୳͠ɺ நԽ͢Δ
/**
* Updates message layout with a newly received message data.
*/
fun ...(receivedMessageData: MessageData) {
messageView.text = receivedMessageData.contentText
senderNameView.text = receivedMessageData.senderName
timestampView.text = receivedMessageData.sentTimeText
}
ίϝϯτ > υΩϡϝϯςʔγϣϯ > ཁ
Slide 34
Slide 34 text
ཁͷϑΥʔϚοτ
ඪ४ϥΠϒϥϦɾAPI ͷॻ͖ํʹ४ͣΔ ྫ: Kotlin, Java, Swift, Objective-C
- Ϋϥε, ม: ໊ࢺ۟
ྫ: "A generic ordered collection of elements."4
- ؔ: ࡾਓশ୯ͷ ಈࢺ Ͱ࢝·ΔϑϨʔζ
ྫ: "Adds a new element at the end of the array."5
5 https://developer.apple.com/documentation/swift/array/3126937-append
4 https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-list/#list
ίϝϯτ > υΩϡϝϯςʔγϣϯ > ཁ
༷ͱ͍ํ
యܕతͳ͍ํ ͱ ظ͢Δಈ࡞ ʹ͍ͭͯॻ͘
/**
* ...
* To update view components such as message text and sender name,
* give [MessageData] model object to [bindView].
*/
class MessageViewPresenter(messageView: View)
ίϝϯτ > υΩϡϝϯςʔγϣϯ > ৄࡉ
੍ͱΤϥʔ
ࣄલ݅ ҧ࣌ͷಈ࡞ ʹ͍ͭͯίϝϯτ͢Δ
- ؔݺͼग़࣌͠ͷ Ϩγʔόͷ݅
- ࣮Ҿͷ੍
/**
* ... [prepare] must be called before calling [play] or [seek],
* or this throws [ResourceNotReadyException].
*/
class VideoPlayer(videoPath: String)
ίϝϯτ > υΩϡϝϯςʔγϣϯ > ৄࡉ
Slide 48
Slide 48 text
੍ͱΤϥʔ
ࣄલ݅ ҧ࣌ͷಈ࡞ ʹ͍ͭͯίϝϯτ͢Δ
- ؔݺͼग़࣌͠ͷ Ϩγʔόͷ݅
- ࣮Ҿͷ੍
/**
* ...
* Returns `null` if the given `position` is out of the array range.
*/
fun valueAt(position: Int): T?
ίϝϯτ > υΩϡϝϯςʔγϣϯ > ৄࡉ
ྫ
ྫΛ༷ͬͯͷཧղΛॿ͚Δ
- ͍ํͷྫ
- ࣮ҾͱΓͷྫ
/**
* ... For example, this returns `listOf("a", "bc", "", "d")`
* for argument `"a, bc ,,d"`
*/
fun splitByComma(string: String): List {...
ίϝϯτ > υΩϡϝϯςʔγϣϯ > ৄࡉ
େ͖ͳίʔυʹର͢Δίϝϯτ
ίϝϯτͰ ίʔυͷ·ͱ·Γ Λ࡞Γɺ֓ཁΛઆ໌͢Δ
...
val messageKey = ...
val messageData = messageCache[messageKey]
...
if (messageData == null || ...) { // <- When this satisfies?
... // <- Hard to overview code in a nest
}
ίϝϯτ > ඇܗࣜతͳίϝϯτ
Slide 58
Slide 58 text
େ͖ͳίʔυʹର͢Δίϝϯτ
ίϝϯτͰ ίʔυͷ·ͱ·Γ Λ࡞Γɺ֓ཁΛઆ໌͢Δ
// Get message data cache if it's available
val messageKey = ...
val messageData = messageCache[messageKey]
...
// Load message data from DB if there's no cached data.
if (messageData == null || ...) {
...
}
ίϝϯτ > ඇܗࣜతͳίϝϯτ
ϫʔΫΞϥϯυΛؚΉίʔυʹର͢Δίϝϯτ
ϫʔΫΞϥϯυͰԿΛ͢Δ͔ɾͳͥඞཁͳͷ͔Λઆ໌͢Δ
// We restore the previous state here
// because libraryFunction() may break the receiver state
ৄࡉΛΔͨΊͷϦϯΫΛՃ͢Δ
// To avoid Device-X specific tinting bug (see, ISSUE-123456)
ίϝϯτ > ඇܗࣜతͳίϝϯτ