Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Go言語100Tips No.1~5 まとめ

Go言語100Tips No.1~5 まとめ

Go言語100Tips No.1~5をまとめました。

Tomoki Ota

May 31, 2024
Tweet

More Decks by Tomoki Ota

Other Decks in Programming

Transcript

  1. JOJU Λ࢖ͬͯ΋͍͍ͱ͖  JOJU͕ࣦഊ͢Δ͜ͱ͸ͳ͍ IBOEMFS͕OJMͰ͸ͳ͍ͷͰɺύχ οΫʹͳΒͳ͍   άϩʔόϧม਺Λ࡞Δඞཁ͕ͳ͍ 

    ୯ମςετʹӨڹΛ༩͑Δ͜ͱ͕ ͳ͍ GoͷެࣜϒϩάͰ͸੩తͳHTTPઃఆΛ ߦ͏ͨΊʹinitؔ਺Λ࢖༻͍ͯ͠Δɻ 43
  2. (PͷJOUFSGBDFͷࢥ૝ “Don’t design with interfaces, discover them.” By Rob Pike

    ΠϯλʔϑΣΠεͰઃܭ͢ΔͷͰ͸ͳ͘ɺΠ ϯλʔϑΣΠεΛൃݟ͢Δɻ 72
  3. (PͷJOUFSGBDFͷࢥ૝ “The bigger the interface, the weaker the abstraction.” By

    Rob Pike ΠϯλʔϑΣΠε͕େ͖͚Ε͹େ͖͍΄Ͳ ந৅Խ͸ऑ͘ͳΔ 90
  4. Ϧείϑͷஔ׵ݪଇ -41 -JTLPW4VCTUJUVUJPO1SJODJQMF φ(x) Λܕ T ͷΦϒδΣΫτ x ʹؔͯ͠ূ໌Մೳͳੑ࣭ͱ͢Δɻ͜ͷͱ͖ɺП(y) ͸

    ܕ T ͷαϒλΠϓ S ͷΦϒδΣΫτ y ʹ͍ͭͯਅͰͳ͚Ε͹ͳΒͳ͍ɻ B. Liskov and J. WingɺA Behavioral Notion of Subtyping 105
  5. Ϧείϑͷஔ׵ݪଇ -41 -JTLPW4VCTUJUVUJPO1SJODJQMF ʮαϒλΠϓʯͷΦϒδΣΫτ͸ผͷܕʢʮεʔύʔλΠϓʯʣͷΦϒδΣΫτͷ ͢΂ͯͷৼΔ෣͍ͱɺߋʹผͷԿ͔Λඋ͑ͨ΋ͷͰ͋Δɻ ͜͜Ͱඞཁͱ͞ΕΔ΋ ͷ͸ɺҎԼʹࣔ͢ஔ׵ͷੑ࣭ͷΑ͏ͳ΋ͷͩΖ͏ɿܕ S ͷ֤ΦϒδΣΫτ o1

    ʹର ͠ɺܕTͷΦϒδΣΫτ o2 ͕ଘࡏ͠ɺT ʹؔͯ͠ఆٛ͞Εͨ͢΂ͯͷϓϩάϥϜ P ͕ o1 Λ o2 Ͱஔ͖׵͑ͯ΋ಈ࡞Λม͑ͳ͍৔߹ɺS ͸ T ͷαϒλΠϓͰ͋Δ B. LiskovɺData Abstraction and HierarchyɺLiskov 1988, p. 25, 3.3. Type Hierarchy 106
  6. αϒλΠϓ ೿ੜܕ ͱ͸ʁ αϒλΠϓ 4VCUZQF ͱ͸ɺJTBͷؔ܎ʹ͋Δ΋ͷɻ ΄ͱΜͲͷαϒλΠϓ͸4VCTUJUVBCMJUZ ަ׵Մೳੑ Λ࣋ ͭɻ

    ͭ·ΓɺαϒλΠϓ ೿ੜܕ ʹґଘͯ͠͸͍͚ͳ͍ɻ αϒλΠϓ͸ɺ೿ੜ΋ͱͷํʹஔ׵ՄೳͰͳ͚Ε͹ ͳΒͳ͍ɻ 107
  7. ৼΔ෣͍ͷ੍ݶ JOU$PO fi H(FUUFS͸ɺ/FX'PPϑΝΫ τϦؔ਺ʹ஫ೖ͞Ε͍ͯΔɻ JOU$PO fi Hߏ଄ମ͸JOU$PO fi H(FUUFSΛ

    ࣮૷͍ͯ͠ΔͷͰɺ/FX'PPϑΝΫτ Ϧؔ਺ͷҾ਺ͱͯ͠౉͢͜ͱ͕Ͱ͖ɺ /FX'PPؔ਺ͷΫϥΠΞϯτʹ͸Өڹ Λ༩͑ͳ͍ɻ #BS͸ઃఆ஋ͷऔಘͷΈͰɺߋ৽͸Ͱ ͖ͳ͍ɻ 138
  8. μοΫλΠϐϯάͱ͸ʁ If it walks like a duck and quacks like

    a duck, it must be a duck. by Dave Thomas ΋͠΋ͦΕ͕ΞώϧͷΑ͏ʹา͖ɺΞώϧͷΑ͏ʹ໐͘ͷͳΒɺͦΕ͸Ξώϧʹҧ͍ͳ͍ 141