哲学とSwiftの発表

6a55a7fb19c1fa78e86ddca7a69db088?s=47 Yuka Ezura
September 08, 2017

 哲学とSwiftの発表

社内勉強会での資料
## ギリシャ哲学とオブジェクト指向の話
* プラトン
* アリストテレス
## Swift
* lazyをletで宣言できるようにする話
* Swift のコンパイラをいじった話

6a55a7fb19c1fa78e86ddca7a69db088?s=128

Yuka Ezura

September 08, 2017
Tweet

Transcript

  1. iOS ࣾ಺ษڧձ 2017/9/8 ezura

  2. ۙگ • ఩ֶΛֶͼ࢝Ίͨ

  3. ۙگ • ఩ֶΛֶͼ࢝Ίͨ ΪϦγϟ఩ֶ

  4. ۙگ • ఩ֶΛֶͼ࢝Ίͨ ΪϦγϟ఩ֶ Θ͔Μͳ͍ʼʻ
 ผ్Ͱ఩ֶ΋ֶ΅͏…

  5. զʑ͕ݟ͍ͯΔੈքͷ ਅ࣮͸Կͳͷ͔

  6. “ਅ”ͱ͸ “ળ”ͱ͸ “ඒ”ͱ͸

  7. ͦΕΒͷຊ࣭͸Կͳͷ͔ զʑ͸Կͳͷ͔

  8. ੈքΛߏ੒͢Δ΋ͷ͸ ҰମͳΜͳͷ͔

  9. ੈքΛߏ੒͢Δ΋ͷ͸ ҰମͳΜͳͷ͔

  10. ੈքΛߏ੒͢Δ΋ͷ͸ ҰମͳΜͳͷ͔ ΦϒδΣΫτࢦ޲ͷੈքͰͷදݱɺ
 ΦϒδΣΫτͷଊ͑ํ
 class, interface, method, …

  11. None
  12. ϓϥτϯ ΞϦετςϨε ιΫϥςε

  13. None
  14. ϓϥτϯͷઆ • ӬԕͰීวͳΔଘࡏɺਅͷଘࡏ
 ΠσΞ • ΠσΞքͱײ֮ੈք͕͋Δ

  15. ϓϥτϯͷઆ

  16. ϓϥτϯͷઆ • അͩ

  17. ϓϥτϯͷઆ • അͩ

  18. ϓϥτϯͷઆ • അͩ • ͳͥഅͩͱࢥ͏ͷ͔

  19. ϓϥτϯͷઆ • അͩ • ͳͥഅͩͱࢥ͏ͷ͔ • େ͖͞΍৭ͳͲɺ׬શʹಉ͡Ͱ͸ͳ ͍ͷʹɺͳͥഅͩͱ൑அͰ͖Δͷ͔

  20. ϓϥτϯͷઆ • അͩ • ͳͥഅͩͱࢥ͏ͷ͔ • େ͖͞΍৭ͳͲɺ׬શʹಉ͡Ͱ͸ͳ ͍ͷʹɺͳͥഅͩͱ൑அͰ͖Δͷ͔ • അͨΒ͠ΊΔ΋ͷ͸Կ͔

  21. ϓϥτϯͷઆ • അͩ • ͳͥഅͩͱࢥ͏ͷ͔ • େ͖͞΍৭ͳͲɺ׬શʹಉ͡Ͱ͸ͳ ͍ͷʹɺͳͥഅͩͱ൑அͰ͖Δͷ͔ • അͨΒ͠ΊΔ΋ͷ͸Կ͔

    • ͳͥഅ͸ෳ਺ଘࡏͰ͖Δͷ͔
  22. ΠσΞք ײ֮ੈք

  23. ΠσΞք ײ֮ੈք

  24. ΠσΞք ײ֮ੈք class അ { property method }ɹ instance instance

    instance
  25. ΠσΞք ײ֮ੈք class അ { property method }ɹ instance instance

    instance ීวͰӬԕͳ΋ͷ มԽ͠
 ੜ੒ɾফ໓͢Δ΋ͷ
  26. ϓϥτϯͷઆ • ӬԕͰීวͳΔଘࡏɺਅͷଘࡏ
 ΠσΞ = ܕ • ΠσΞքͱײ֮ੈք͕͋Δ
 ܕͷੈքͱΠϯελϯεͷੈք

  27. ϓϥτϯͷઆ • ӬԕͰීวͳΔଘࡏɺਅͷଘࡏ
 ΠσΞ = ܕ • ΠσΞքͱײ֮ੈք͕͋Δ
 ܕͷੈքͱΠϯελϯεͷੈք ΠσΞք

    Ͳ͔͜ผͷੈք
  28. ϓϥτϯ ΞϦετςϨε ιΫϥςε

  29. ΞϦετςϨεͷઆ • ΋ͷ͸”ܗ૬ͱ࣭ྉ(eidosͱhyle)”Ͱ
 Ͱ͖͍ͯΔ • 4ݪҼ࿦

  30. ΞϦετςϨεͷઆ • അͩ

  31. ΞϦετςϨεͷઆ • അͩ

  32. ΞϦετςϨεͷઆ • അͩ • ͳͥഅͳͷ͔

  33. ΞϦετςϨεͷઆ • അͩ • ͳͥഅͳͷ͔ • അͱ͸ • ૸Δ •

    ஆ͔͍ • …
  34. ΞϦετςϨεͷઆ • അͩ • ͳͥഅͳͷ͔ • അͱ͸ • ૸Δ •

    ஆ͔͍ • … ੑ࣭ͷू·Γ
  35. ੑ࣭ ੑ࣭ ੑ࣭ ੑ࣭ ෺࣭తͳ΋ͷ
 (΋ͷΛ۩৅Խͤ͞Δ΋ͷ) ʴ → ܗ૬ ܗ࣭

  36. class അ { property method }ɹ ܗ૬ ࣭ྉ

  37. ϓϥτϯ ΞϦετςϨε ੑ࣭ ੑ࣭ ੑ࣭

  38. ϓϥτϯ ΞϦετςϨε ੑ࣭ ੑ࣭ ੑ࣭ 4ݪҼ࿦͔Β
 ࣮ମΛ؍࡯

  39. ۙگใࠂऴΘΓ

  40. ۙگใࠂऴΘΓ

  41. ࣗ༝ݚڀ • lazy ͳϓϩύςΟΛ let Ͱѻ͏ • Optional Λจࣈྻม׵ͨ͠ͱ͖ʹ “Optional(“text”)”

    ʹͳ ΔͷΛ΍͚ͬͭΔ protocol
  42. lazy ͳϓϩύςΟΛ let Ͱѻ͏

  43. ಈػ swift͸lazyΛval/letʹͰ͖ͳ͍͔ΒΫι ‧‪‬‭⛺è䡢(’ω’)䡢è⛺䡡‬‪‧ ͱ͋Δͷਓ

  44. swift kotlin

  45. swift kotlin ↓

  46. swift kotlin kotlin ͷ lazy ͸ function ↓

  47. swift kotlin ↓ kotlin ͷ lazy ͸ function Lazy ܕ

  48. kotlin ͷ Lazy property Lazy value ॳظԽͷΫϩʔδϟ get delegation

  49. Swift Ͱͷ࣮૷ public class Lazy<T> { private let initializer: ()

    -> T private var _value: T! public var value: T { // TODO: mutex switch _value { case .none: _value = initializer() return _value case .some(let v): return v } } public init(initializer: @escaping () -> T) { self.initializer = initializer } } public func lazy<T>(initializer: @escaping () -> T) -> Lazy<T> { return Lazy(initializer: initializer) }
  50. swift kotlin ↓

  51. swift kotlin ↓

  52. swift kotlin ↓ (‘ω’ )

  53. swift kotlin ↓ (‘ω’ )
 Swift3 ·Ͱ͸ `v[]`Ͱ͖ͨΜͩ…
 ͜Μͳ͸ͣ͡Όͳ͔ͬͨΜͩ…

  54. swift kotlin ↓ let ʹ͸Ͱ͖͔ͨΒ

  55. Optional Λจࣈྻม׵ͨ͠ͱ͖ʹ “Optional(“text”)” ʹͳΔͷΛ΍͚ͬͭΔ protocol

  56. Optional Λจࣈྻม׵ͨ͠ͱ͖ʹ “Optional(“text”)” ʹͳΔͷΛ΍͚ͬͭΔ protocol ஫:ݸਓతʹ͸ “Optional(“text”)”ͬͯͳΔͷɺ
 Optionalͷૢ࡞ϛεʹର͢ΔռΊΈ͍ͨͰ޷͖Ͱ͢

  57. extension Optional: CustomStringConvertible { public var description: String { switch

    self { case .none: return "" case .some(let wrapped): return "\(wrapped)" } } } "\("sss" as Optional)" ͖ͬ͞ؾ͍͚ͮͨͲɺ
 ͜ΕͰࡁΜͩ ͔ͤͬ͘΍͔ͬͨΒɺ
 ଞͷ΍Γํ΋࿩͠·͢ʂ
  58. "\(Normal() as Optional)" // -> "Optional(description)" "\(Force() as Optional)" //

    -> "description" // ------------------ struct Normal: CustomStringConvertible { var description: String { return "\(#function)" } } struct Force: CustomForceStringConvertible { var description: String { return "\(#function)" } } Goal
  59. "\(Normal() as Optional)" // -> "Optional(description)" "\(Force() as Optional)" //

    -> "description" // ------------------ struct Normal: CustomStringConvertible { var description: String { return "\(#function)" } } struct Force: CustomForceStringConvertible { var description: String { return "\(#function)" } } Goal զʑͷׯবͰ͖Δ෦෼
  60. "\(Normal() as Optional)" // -> "Optional(description)" "\(Force() as Optional)" //

    -> "description" // ------------------ struct Normal: CustomStringConvertible { var description: String { return "\(#function)" } } struct Force: CustomForceStringConvertible { var description: String { return "\(#function)" } } Goal զʑͷׯবͰ͖Δ෦෼ Λ௒͑ͳͯ͘͸͍͚ͳ͍
  61. "\(Normal() as Optional)" // -> "Optional(description)" "\(Force() as Optional)" //

    -> "description" // ------------------ struct Normal: CustomStringConvertible { var description: String { return "\(#function)" } } struct Force: CustomForceStringConvertible { var description: String { return "\(#function)" } } Goal զʑͷׯবͰ͖Δ෦෼ Λ௒͑ͳͯ͘͸͍͚ͳ͍
  62. खॱ • Swift ͷϓϩδΣΫτΛ࣋ͬͯདྷΔ • cmake ͱ ninja Λ࣋ͬͯདྷΔ •

    ࠷৽ͷ Xcode Λࢦఆ͢Δ • ม׵จࣈྻΛܾఆ͢Δͱ͜ΖΛม͑Δ
 (https://github.com/ezura/swift/commit/ 6e782f69265224a3b5321f9315039d36428dfcc7) • ίϯύΠϧ
  63. "\(Normal() as Optional)" // -> "Optional(description)" "\(Force() as Optional)" //

    -> "description" // ------------------ struct Normal: CustomStringConvertible { var description: String { return "\(#function)" } } struct Force: CustomForceStringConvertible { var description: String { return "\(#function)" } }
  64. ͍ͭͰʹ Lazy ΋૊ΈࠐΈ·ͨ͠
 https://github.com/ezura/swift/commit/ 7946a66674f696836321df8d9b189ae0a804eb4c

  65. ͝੩ௌ
 ͋Γ͕ͱ͏͍͟͝·ͨ͠