code ▸ A codebase that allows us to continue to move at a fast pace ▸ Graceful recovery from “unexpected” errors while minimizing user impact ▸ No “denial of service” crashing ▸ Avoid asking the user to try reinstalling the app ▸ ҆ఆత͔ͭਖ਼ৗʹಈ࡞͢Δίʔυ ▸ ։ൃεϐʔυΛམͱͣ͞ʹਐΊΒΕΔ ▸ ͍ΘΏΔ༧ظ͠ͳ͍ෆ۩߹͔Β෮ؼ͠, ϢʔβʔͷӨڹൣғΛ࠷খݶʹ ▸ DoS తʹམͪͳ͍Α͏ʹҙ͢Δ ▸ ΞϓϦͷ࠶ΠϯετʔϧΛͳΔ͘ ͤ͞ͳ͍Α͏ʹ എܠ
at any given time ▸ Mostly defined by order of imperative code ▸ Usually implicit, but can be made more explicit ▸ Comments ▸ Not being compilable in incorrect order ▸ ࣌ؒత ▸ ͋Δ࣌ؒͰ࣮ߦ͞Ε͍ͯΔίʔυΛࣔ͢ ▸ ໋ྩܕίʔυͷॱ൪ʹΑͬͯఆٛ͞ΕΔ ▸ େ֓҉త͕ͩɺΑΓ໌ࣔతʹ͢Δ͜ͱ Մೳ ▸ ίϝϯτ ▸ ؒҧͬͨॱ൪ͰίϯύΠϧͰ͖ͳ͍Α ͏ʹ͢Δ͜ͱ ঢ়ଶ
stored in user defaults. ▸ It should be migrated on first launch after upgrading the app. ▸ User defaults ʹ֨ೲ͞Ε͕ͨରɻ ▸ ΞϓϦͷΞοϓσʔτޙͷॳظىಈ࣌ ʹҠߦ͢Δɻ σʔλܗࣜͷҠߦॲཧ
was used prior to migration. ▸ Shared state + ambiguous dependency ▸ How do we go about fixing it? ▸ How do we prevent similar mistakes? ▸ Ҡߦ͢Δલʹར༻͞Εͯ͠·ͬͨɻ ▸ ڞ༗ঢ়ଶͱᐆດͳґଘؔ ▸ मਖ਼ํ๏ʁ ▸ ࠶ൃࢭʁ σʔλܗࣜͷҠߦॲཧ
don't have an instance of a type, you can't call a function that requires it as input. ▸ Create the type to represent the transition into a certain state. ▸ Requiring an instance of that type as a function parameter allows you to specify the state that the type represents as a prerequisite. ▸ ܕͷΠϯελϯε͕ͳ͚ΕͦΕΛҾͱ͢ ΔؔΛݺͼग़͢͜ͱ͕Ͱ͖ͳ͍ɻ ▸ ಛఆͷঢ়ଶͷભҠΛද͢ܕΛ࡞Δɻ ▸ ͦͷܕͷΠϯελϯεΛҾͱͯ͠ड͚औΔ ͜ͱʹΑͬͯͦͷܕ͕ද͢ঢ়ଶΛલఏ݅ͱ ͯ͠ఆٛ͢Δ͜ͱ͕Ͱ͖Δɻ ܕʹΑΔ໌ࣔతͳґଘؔ
wrong”, “present or not present” semantics as output ▸ As input, “optional” semantics ▸ Swift’s syntax makes it easy to safely handle. ▸ The “go to” choice ▸ ग़ྗͷͱͯ͠ʮਖ਼͍͔͠ਖ਼͘͠ͳ͍ʯ ʮ༗Γ͔ແ͠ʯͷҙຯ ▸ ೖྗͷͱͯ͠ʮҙʯͷҙຯ ▸ ҆શʹѻ͏͜ͱ͕༰қʹͰ͖Δ ▸ େͷ߹ Optional ܕ͕ਖ਼ղ
“unable to complete successfully” semantics ▸ Often used for “fatal errors” ▸ Syntax lets you pretend nothing will go wrong at the call site of throwing functions. ▸ Best suited for handling low- probability, high-impact errors. ▸ ಉ͡Α͏ͳʮෆਖ਼ղʯʮਖ਼ৗʹॲཧ Ͱ͖ͳ͔ͬͨʯҙຯ ▸ க໋తͳʹΘΕΔ͜ͱ͕ଟ͍ ▸ εϩʔ͢Δؔͷݺͼग़͠ଆਖ਼ৗʹ ॲཧ͞ΕΔৼΔ͍͕Ͱ͖Δ ▸ ൃੜ͕͘Өڹൣғ͕͍Τϥʔʹ ར༻͢Δͷ͕ద ERROR ͷ͍ಓ
cognizant of input/output flow leads to more robust code. ▸ Be aware of code critically important. ▸ Use Optional for lightweight, low- context, somewhat likely errors. ▸ Use Error for heavyweight, high- context, and unlikely errors. ▸ ೖग़ྗͷྲྀΕΛҙ͍ࣝͯ͠Ε͋ΒΏ ΔΤϥʔঢ়ଶΛରॲͰ͖ΔΑ͏ʹίʔ υ͕ͳ͍ͬͯ͘ɻ ▸ ඇৗʹॏཁͳίʔυʹؾΛ͚ͭΔ͜ͱ ▸ Optionalใྔ͕গͳ͍ൃੜස ͕ى͜Γ͕ͪͳΤϥʔʹ ▸ Error ใྔ͕ଟ͍كͳΤϥʔʹ ·ͱΊ