Golang で心を無にしてコードを書く

Golang で心を無にしてコードを書く

LINE Developer Meetup #11 での LT スライド。Golang の語り尽くされたであろう、単純さについて入門的にふれる話。

6/22 19:00 宮崎開催! LINE Developer Meetup #11 - connpass http://connpass.com/event/15986/

1548544cf8076a7c011b6717186f1710?s=128

Tomoya Kose

June 22, 2015
Tweet

Transcript

  1. GolangͰ৺Λແʹͯ͠ίʔυΛॻ͘ mitsuse@github LINE Developer Meetup #11

  2. ͓·͑ɺͩΕΑɻ

  3. ͓·͑ɺͩΕΑɻ

  4. ͓·͑ɺͩΕΑɻ ɾಸྑͰࣗવݴޠॲཧ΍ͬͯͨ

  5. ͓·͑ɺͩΕΑɻ ɾಸྑͰࣗવݴޠॲཧ΍ͬͯͨ ɾݩPythonistaͰGopherͰVimmer

  6. ͓·͑ɺͩΕΑɻ ɾಸྑͰࣗવݴޠॲཧ΍ͬͯͨ ɾ࢓ࣄͰ͸Scalaॻ͍ͯΔɾAkkaྑ͍ ɾݩPythonistaͰGopherͰVimmer

  7. ͓·͑ɺͩΕΑɻ ɾಸྑͰࣗવݴޠॲཧ΍ͬͯͨ ɾGoCon 2015ࢀՃࣦഊ͠·ͨ͠ ɾݩPythonistaͰGopherͰVimmer ɾ࢓ࣄͰ͸Scalaॻ͍ͯΔɾAkkaྑ͍

  8. Golangॻ͍ͯ·͔͢ʁ

  9. Golangͱ͸ Go is an open source programming language that makes

    it easy to build simple, reliable, and efficient software. The Go Programming Language https://golang.org/
  10. Golangͱ͸ Go is an open source programming language that makes

    it easy to build simple, reliable, and efficient software. The Go Programming Language https://golang.org/
  11. Golangͱ͸ Go is an open source programming language that makes

    it easy to build simple, reliable, and efficient software. The Go Programming Language https://golang.org/
  12. Golangͱ͸ Go is an open source programming language that makes

    it easy to build simple, reliable, and efficient software. The Go Programming Language https://golang.org/
  13. Golangͱ͸ Go is an open source programming language that makes

    it easy to build simple, reliable, and efficient software. The Go Programming Language https://golang.org/
  14. Golangͱ͸ Go is an open source programming language that makes

    it easy to build simple, reliable, and efficient software. The Go Programming Language https://golang.org/ γϯϓϧͰ৴པੑͷ͋Δޮ཰ͷྑ͍ιϑτ΢ΣΞͷߏஙΛָʹʂ
  15. ͳͥॻ͘ͷ͔ɿ ৺Λແʹͯ͠ॻ͘ͷʹௐ౓ྑ͍͔Β

  16. ͳͥॻ͘ͷ͔ɿ ৺Λແʹͯ͠ॻ͘ͷʹௐ౓ྑ͍͔Β ॆ࣮ͨ͠πʔϧ܈ʹΑΔαϙʔτɻ goίϚϯυʹϏϧυɾςετɾίʔυ੔ܗɾੜ੒ͳͲͷπʔϧ͕ू໿

  17. ͳͥॻ͘ͷ͔ɿ ৺Λແʹͯ͠ॻ͘ͷʹௐ౓ྑ͍͔Β ॆ࣮ͨ͠πʔϧ܈ʹΑΔαϙʔτɻ ੩తܕ෇͚ͳμοΫλΠϐϯάͰ໘౗͘͘͞ͳ͍ɻ ίϯύΠϧ࣌ʹܕνΣοΫͯ͠΄͍͚͠Ͳɺؾ࣋ͪ͸--࢖͍Ͱ͍͍ͨ goίϚϯυʹϏϧυɾςετɾίʔυ੔ܗɾੜ੒ͳͲͷπʔϧ͕ू໿

  18. ͳͥॻ͘ͷ͔ɿ ৺Λແʹͯ͠ॻ͘ͷʹௐ౓ྑ͍͔Β ॆ࣮ͨ͠πʔϧ܈ʹΑΔαϙʔτɻ ੩తܕ෇͚ͳμοΫλΠϐϯάͰ໘౗͘͘͞ͳ͍ɻ ࠇຐज़͕ͳ͍ɻݟͨ໨ͦͷ··ʹಈ͘ɻ ίϯύΠϧ࣌ʹܕνΣοΫͯ͠΄͍͚͠Ͳɺؾ࣋ͪ͸--࢖͍Ͱ͍͍ͨ ҉໧తܕม׵ͱ͔ϚΫϩͱ͔ڧྗ͚ͩͲɺͦΕΑΓ͸ಡΈ΍͢͞ॏࢹ goίϚϯυʹϏϧυɾςετɾίʔυ੔ܗɾੜ੒ͳͲͷπʔϧ͕ू໿

  19. ࢲͷ৔߹ɿPython͔ΒGolang΁

  20. ࢲͷ৔߹ɿPython͔ΒGolang΁ Python͸ྑ͍ͷ͕ͩʜ

  21. ࢲͷ৔߹ɿPython͔ΒGolang΁ ɾ੩తܕνΣοΫ͍ͨ͠ Python͸ྑ͍ͷ͕ͩʜ

  22. ࢲͷ৔߹ɿPython͔ΒGolang΁ ɾ੩తܕνΣοΫ͍ͨ͠ ɾ͋Δఔ౓ߴ଎ʹಈ͔͍ͨ͠ Python͸ྑ͍ͷ͕ͩʜ

  23. ࢲͷ৔߹ɿPython͔ΒGolang΁ ɾ੩తܕνΣοΫ͍ͨ͠ ɾ͋Δఔ౓ߴ଎ʹಈ͔͍ͨ͠ ɾฒߦॲཧɾฒྻॲཧΛָʹॻ͖͍ͨ Python͸ྑ͍ͷ͕ͩʜ

  24. ࢲͷ৔߹ɿPython͔ΒGolang΁ ɾ੩తܕνΣοΫ͍ͨ͠ ɾ͋Δఔ౓ߴ଎ʹಈ͔͍ͨ͠ ɾฒߦॲཧɾฒྻॲཧΛָʹॻ͖͍ͨ ɾ͚ͲɺίϯύΠϧ΍ϏϧυπʔϧͰਏ͘ͳΓͨ͘ͳ͍ Python͸ྑ͍ͷ͕ͩʜ

  25. ࢲͷ৔߹ɿPython͔ΒGolang΁ ɾ੩తܕνΣοΫ͍ͨ͠ ɾ͋Δఔ౓ߴ଎ʹಈ͔͍ͨ͠ ɾฒߦॲཧɾฒྻॲཧΛָʹॻ͖͍ͨ ɾ͚ͲɺίϯύΠϧ΍ϏϧυπʔϧͰਏ͘ͳΓͨ͘ͳ͍ ͦΕɺGolangͰͰ͖ΔΑʂ Python͸ྑ͍ͷ͕ͩʜ

  26. ୯७Ͱ෼͔Γ΍͍͢πʔϧ܈

  27. HPSVOͱΓ͋͑ͣίϯύΠϧ࣮ͯ͠ߦ͢Δ

  28. HPSVOͱΓ͋͑ͣίϯύΠϧ࣮ͯ͠ߦ͢Δ 1 package main 2 3 import ( 4 "fmt"

    5 ) 6 7 func main() { 8 fmt.Println("Hello, world!") 9 } ίϯύΠϧɾ࣮ߦΛ͓͜ͳ͏ɻ ɾίϯύΠϧ͸ߴ଎ ɾ͍ΘΏΔ--తͳؾ࣋ͪͰ࣮ߦ
  29. HPSVOͱΓ͋͑ͣίϯύΠϧ࣮ͯ͠ߦ͢Δ 1 package main 2 3 import ( 4 "fmt"

    5 ) 6 7 func main() { 8 fmt.Println("Hello, world!") 9 } $ go run main.go ίϯύΠϧɾ࣮ߦΛ͓͜ͳ͏ɻ ɾίϯύΠϧ͸ߴ଎ ɾ͍ΘΏΔ--తͳؾ࣋ͪͰ࣮ߦ
  30. HPSVOͱΓ͋͑ͣίϯύΠϧ࣮ͯ͠ߦ͢Δ 1 package main 2 3 import ( 4 "fmt"

    5 ) 6 7 func main() { 8 fmt.Println("Hello, world!") 9 } $ go run main.go ίϯύΠϧɾ࣮ߦΛ͓͜ͳ͏ɻ ɾίϯύΠϧ͸ߴ଎ ɾ͍ΘΏΔ--తͳؾ࣋ͪͰ࣮ߦ ʮͱΓ࣮͋͑ͣߦʯ͕ؾܰʹͰ͖Δ $ go run main.go Hello, world!
  31. HPSVOͱΓ͋͑ͣίϯύΠϧ࣮ͯ͠ߦ͢Δ 1 package main 2 3 import ( 4 "fmt"

    5 ) 6 7 func main() { 8 fmt.Println("Hello, world!") 9 } $ go run main.go $ go run main.go Hello, world! ίϯύΠϧɾ࣮ߦΛ͓͜ͳ͏ɻ ɾίϯύΠϧ͸ߴ଎ ɾ͍ΘΏΔ--తͳؾ࣋ͪͰ࣮ߦ ։ൃऀͰ͋ΔRob Pikeࢯ͍Θ͘ʮಛผ଎͍Θ͚Ͱ͸ͳ͍ɻ஗͘ͳΔ͜ͱΛ΍ͬͯͳ͍͚ͩɻʯͱͷ͜ͱ ʮͱΓ࣮͋͑ͣߦʯ͕ؾܰʹͰ͖Δ https://twitter.com/Morikuma_Works/status/538961275779162112
  32. HPGNUίʔυΛ੔͑Δ

  33. HPGNUίʔυΛ੔͑Δ ίʔυϑΥʔϚολʔ͕ެࣜʹఏڙ͞Ε͍ͯΔɻ

  34. HPGNUίʔυΛ੔͑Δ ίʔυϑΥʔϚολʔ͕ެࣜʹఏڙ͞Ε͍ͯΔɻ ɾελΠϧͷ౷Ұͱ͍͏ ॏཁ͚ͩͲ ෆໟͳٞ࿦͕ى͖ͳ͍ɻ

  35. HPGNUίʔυΛ੔͑Δ ίʔυϑΥʔϚολʔ͕ެࣜʹఏڙ͞Ε͍ͯΔɻ ɾελΠϧͷ౷Ұͱ͍͏ ॏཁ͚ͩͲ ෆໟͳٞ࿦͕ى͖ͳ͍ɻ ɾίʔυΛॻ͘͜ͱʹूதͰ͖Δɻอଘ࣌ʹࣗಈͰϑΥʔϚοτɻ

  36. HPGNUίʔυΛ੔͑Δ 1 package main 2 3 4 import ( 5

    "fmt" 6 ) 7 8 func main(){ 9 fmt.Println( "Hello, world!") } ίʔυϑΥʔϚολʔ͕ެࣜʹఏڙ͞Ε͍ͯΔɻ ɾελΠϧͷ౷Ұͱ͍͏ ॏཁ͚ͩͲ ෆໟͳٞ࿦͕ى͖ͳ͍ɻ ɾίʔυΛॻ͘͜ͱʹूதͰ͖Δɻอଘ࣌ʹࣗಈͰϑΥʔϚοτɻ
  37. HPGNUίʔυΛ੔͑Δ 1 package main 2 3 4 import ( 5

    "fmt" 6 ) 7 8 func main(){ 9 fmt.Println( "Hello, world!") } ίʔυϑΥʔϚολʔ͕ެࣜʹఏڙ͞Ε͍ͯΔɻ $ go fmt main.go ɾελΠϧͷ౷Ұͱ͍͏ ॏཁ͚ͩͲ ෆໟͳٞ࿦͕ى͖ͳ͍ɻ ɾίʔυΛॻ͘͜ͱʹूதͰ͖Δɻอଘ࣌ʹࣗಈͰϑΥʔϚοτɻ
  38. HPGNUίʔυΛ੔͑Δ 1 package main 2 3 4 import ( 5

    "fmt" 6 ) 7 8 func main(){ 9 fmt.Println( "Hello, world!") } 1 package main 2 3 import ( 4 "fmt" 5 ) 6 7 func main() { 8 fmt.Println("Hello, world!") 9 } ίʔυϑΥʔϚολʔ͕ެࣜʹఏڙ͞Ε͍ͯΔɻ $ go fmt main.go ɾελΠϧͷ౷Ұͱ͍͏ ॏཁ͚ͩͲ ෆໟͳٞ࿦͕ى͖ͳ͍ɻ ɾίʔυΛॻ͘͜ͱʹूதͰ͖Δɻอଘ࣌ʹࣗಈͰϑΥʔϚοτɻ
  39. HPHFUύοέʔδΛऔಘͯ͠Πϯετʔϧ

  40. HPHFUύοέʔδΛऔಘͯ͠Πϯετʔϧ $ go get -u github.com/mitsuse/bullet ύοέʔδ໊Λࢦఆ͢Δ͚ͩʂϏϧυ͔ΒΠϯετʔϧ·Ͱ׬ྃ͢Δɻ

  41. HPHFUύοέʔδΛऔಘͯ͠Πϯετʔϧ $ go get -u github.com/mitsuse/bullet ύοέʔδ໊Λࢦఆ͢Δ͚ͩʂϏϧυ͔ΒΠϯετʔϧ·Ͱ׬ྃ͢Δɻ Makefile૬౰ϑΝΠϧ΍ґଘؔ܎Λఆٛ͢ΔϑΝΠϧ͕ଘࡏ͠ͳ͍ɻ

  42. HPHFUύοέʔδΛऔಘͯ͠Πϯετʔϧ $ go get -u github.com/mitsuse/bullet ύοέʔδ໊Λࢦఆ͢Δ͚ͩʂϏϧυ͔ΒΠϯετʔϧ·Ͱ׬ྃ͢Δɻ 1 import (

    2 ... 3 "github.com/codegangsta/cli" 4 "github.com/mitsuse/pushbullet-go" 5 "github.com/mitsuse/pushbullet-go/requests" 6 ) Makefile૬౰ϑΝΠϧ΍ґଘؔ܎Λఆٛ͢ΔϑΝΠϧ͕ଘࡏ͠ͳ͍ɻ
  43. HPHFUύοέʔδΛऔಘͯ͠Πϯετʔϧ $ go get -u github.com/mitsuse/bullet ύοέʔδ໊Λࢦఆ͢Δ͚ͩʂϏϧυ͔ΒΠϯετʔϧ·Ͱ׬ྃ͢Δɻ 1 import (

    2 ... 3 "github.com/codegangsta/cli" 4 "github.com/mitsuse/pushbullet-go" 5 "github.com/mitsuse/pushbullet-go/requests" 6 ) import͞ΕͯΔύοέʔδ΋औಘɾϏϧυ Makefile૬౰ϑΝΠϧ΍ґଘؔ܎Λఆٛ͢ΔϑΝΠϧ͕ଘࡏ͠ͳ͍ɻ
  44. HPHFUύοέʔδΛऔಘͯ͠Πϯετʔϧ $ go get -u github.com/mitsuse/bullet ύοέʔδ໊Λࢦఆ͢Δ͚ͩʂϏϧυ͔ΒΠϯετʔϧ·Ͱ׬ྃ͢Δɻ ґଘؔ܎ͷ؅ཧ͸ɺίʔυதͷimport͕݉Ͷ͍ͯΔɻແବ͕ͳ͍ɻ 1 import

    ( 2 ... 3 "github.com/codegangsta/cli" 4 "github.com/mitsuse/pushbullet-go" 5 "github.com/mitsuse/pushbullet-go/requests" 6 ) import͞ΕͯΔύοέʔδ΋औಘɾϏϧυ Makefile૬౰ϑΝΠϧ΍ґଘؔ܎Λఆٛ͢ΔϑΝΠϧ͕ଘࡏ͠ͳ͍ɻ
  45. ܕγεςϜ͕୯७ ܕʹ֊૚ؔ܎͕ͳ͍

  46. ߏ଄ମ(struct)ɿ Goͷߏ଄ମ͸ϝιουΛ࣋ͭ

  47. ߏ଄ମ(struct)ɿ Goͷߏ଄ମ͸ϝιουΛ࣋ͭ 1 package main 2 3 import ( 4

    "fmt" 5 ) 6 7 type Cat struct { 8 name string 9 } 10 11 func (c *Cat) Name() string { 12 return c.name 13 } 14 15 func main() { 16 cat := &Cat{ 17 name: "Rentaro", 18 } 19 20 fmt.Println(cat.Name()) 21 } ߏ଄ମͷΠϯελϯε͔Βυοτ෇͖Ͱϝιουݺͼग़͕͠Մೳɻ
  48. ߏ଄ମ(struct)ɿ Goͷߏ଄ମ͸ϝιουΛ࣋ͭ 1 package main 2 3 import ( 4

    "fmt" 5 ) 6 7 type Cat struct { 8 name string 9 } 10 11 func (c *Cat) Name() string { 12 return c.name 13 } 14 15 func main() { 16 cat := &Cat{ 17 name: "Rentaro", 18 } 19 20 fmt.Println(cat.Name()) 21 } ߏ଄ମͱϑΟʔϧυ ߏ଄ମͷΠϯελϯε͔Βυοτ෇͖Ͱϝιουݺͼग़͕͠Մೳɻ
  49. ߏ଄ମ(struct)ɿ Goͷߏ଄ମ͸ϝιουΛ࣋ͭ 1 package main 2 3 import ( 4

    "fmt" 5 ) 6 7 type Cat struct { 8 name string 9 } 10 11 func (c *Cat) Name() string { 12 return c.name 13 } 14 15 func main() { 16 cat := &Cat{ 17 name: "Rentaro", 18 } 19 20 fmt.Println(cat.Name()) 21 } ߏ଄ମͱϑΟʔϧυ ߏ଄ମ͸ϝιουΛ࣋ͭ ߏ଄ମͷΠϯελϯε͔Βυοτ෇͖Ͱϝιουݺͼग़͕͠Մೳɻ
  50. ߏ଄ମ(struct)ɿ Goͷߏ଄ମ͸ϝιουΛ࣋ͭ 1 package main 2 3 import ( 4

    "fmt" 5 ) 6 7 type Cat struct { 8 name string 9 } 10 11 func (c *Cat) Name() string { 12 return c.name 13 } 14 15 func main() { 16 cat := &Cat{ 17 name: "Rentaro", 18 } 19 20 fmt.Println(cat.Name()) 21 } ߏ଄ମͱϑΟʔϧυ ߏ଄ମ͸ϝιουΛ࣋ͭ {}͔newͰੜ੒ɾॳظԽ ߏ଄ମͷΠϯελϯε͔Βυοτ෇͖Ͱϝιουݺͼग़͕͠Մೳɻ
  51. ΠϯλʔϑΣʔε (interface)ɿ ϝιουఆٛͷू·Γ

  52. ΠϯλʔϑΣʔε (interface)ɿ ϝιουఆٛͷू·Γ 1 type Named interface { 2 Name()

    string 3 } 4 5 type Cat struct { 6 name string 7 } 8 9 func (c *Cat) Name() string { 10 return c.name 11 } .. 21 func printName(n Named) { 22 fmt.Println(n.Name()) 23 } ΠϯλʔϑΣʔεͰϝιουͷγάωνϟΛఆٛ͢Δɻ
  53. ΠϯλʔϑΣʔε (interface)ɿ ϝιουఆٛͷू·Γ 1 type Named interface { 2 Name()

    string 3 } 4 5 type Cat struct { 6 name string 7 } 8 9 func (c *Cat) Name() string { 10 return c.name 11 } .. 21 func printName(n Named) { 22 fmt.Println(n.Name()) 23 } ΠϯλʔϑΣʔε͸ϝιου܈Λఆٛ ΠϯλʔϑΣʔεͰϝιουͷγάωνϟΛఆٛ͢Δɻ
  54. ΠϯλʔϑΣʔε (interface)ɿ ϝιουఆٛͷू·Γ 1 type Named interface { 2 Name()

    string 3 } 4 5 type Cat struct { 6 name string 7 } 8 9 func (c *Cat) Name() string { 10 return c.name 11 } .. 21 func printName(n Named) { 22 fmt.Println(n.Name()) 23 } ΠϯλʔϑΣʔε͸ϝιου܈Λఆٛ *Cat͸Name()ϝιουΛ࣋ͭ ΠϯλʔϑΣʔεͰϝιουͷγάωνϟΛఆٛ͢Δɻ
  55. ΠϯλʔϑΣʔε (interface)ɿ ϝιουఆٛͷू·Γ 1 type Named interface { 2 Name()

    string 3 } 4 5 type Cat struct { 6 name string 7 } 8 9 func (c *Cat) Name() string { 10 return c.name 11 } .. 21 func printName(n Named) { 22 fmt.Println(n.Name()) 23 } ΠϯλʔϑΣʔε͸ϝιου܈Λఆٛ *Cat͸Name()ϝιουΛ࣋ͭ *Cat͸NamedΛຬ͍ͨͯ͠Δ ΠϯλʔϑΣʔεͰϝιουͷγάωνϟΛఆٛ͢Δɻ
  56. ΠϯλʔϑΣʔε (interface)ɿ ϝιουఆٛͷू·Γ 1 type Named interface { 2 Name()

    string 3 } 4 5 type Cat struct { 6 name string 7 } 8 9 func (c *Cat) Name() string { 10 return c.name 11 } .. 21 func printName(n Named) { 22 fmt.Println(n.Name()) 23 } ΠϯλʔϑΣʔε͸ϝιου܈Λఆٛ ΠϯλʔϑΣʔεͰϝιουͷγάωνϟΛఆٛ͢Δɻ ΠϯλʔϑΣʔε͕࣋ͭϝιου܈ͷ࣮૷Λɺߏ଄ମ͕͍࣋ͬͯΔɻ ߏ଄ମ͸ɺͦͷΠϯλʔϑΣʔεܕͱͯ͠ར༻Ͱ͖Δɻ ࣮૷ͯ͠Δ͜ͱΛ໌ࣔ͠ͳͯ͘ྑ͍ɻ੩తͳμοΫλΠϐϯάɻ *Cat͸Name()ϝιουΛ࣋ͭ *Cat͸NamedΛຬ͍ͨͯ͠Δ
  57. ߏ଄ମຒΊࠐΈ (struct embedding)ɿ ҠৡʹΑΔΠϯλʔϑΣʔεͷ࣮૷ύλʔϯ

  58. ߏ଄ମຒΊࠐΈ (struct embedding)ɿ ҠৡʹΑΔΠϯλʔϑΣʔεͷ࣮૷ύλʔϯ 1 type Named interface { 2

    Name() string 3 } 4 5 type Animal struct { 6 name string 7 } 8 9 func (a *Animal) Name() string { 10 return a.name 11 } 12 13 type Cat struct { 14 *Animal 15 } Golangʹ͸ܧঝ͸ͳ͍ɻ ߏ଄ମຒΊࠐΈͰҠৡͯ͠ɺΠϯλʔ ϑΣʔεΛຬͨ͢ύλʔϯɻ
  59. ߏ଄ମຒΊࠐΈ (struct embedding)ɿ ҠৡʹΑΔΠϯλʔϑΣʔεͷ࣮૷ύλʔϯ 1 type Named interface { 2

    Name() string 3 } 4 5 type Animal struct { 6 name string 7 } 8 9 func (a *Animal) Name() string { 10 return a.name 11 } 12 13 type Cat struct { 14 *Animal 15 } *Animal͸Name()ϝιουΛ࣋ͭ ߏ଄ମຒΊࠐΈͰҠৡͯ͠ɺΠϯλʔ ϑΣʔεΛຬͨ͢ύλʔϯɻ Golangʹ͸ܧঝ͸ͳ͍ɻ
  60. ߏ଄ମຒΊࠐΈ (struct embedding)ɿ ҠৡʹΑΔΠϯλʔϑΣʔεͷ࣮૷ύλʔϯ 1 type Named interface { 2

    Name() string 3 } 4 5 type Animal struct { 6 name string 7 } 8 9 func (a *Animal) Name() string { 10 return a.name 11 } 12 13 type Cat struct { 14 *Animal 15 } ಗ໊ϑΟʔϧυ*Animalͷϝιου͸ɺ *Catͷॴ༗෺ͷΑ͏ʹΞΫηεͰ͖Δ ߏ଄ମຒΊࠐΈͰҠৡͯ͠ɺΠϯλʔ ϑΣʔεΛຬͨ͢ύλʔϯɻ Golangʹ͸ܧঝ͸ͳ͍ɻ *Animal͸Name()ϝιουΛ࣋ͭ
  61. ߏ଄ମຒΊࠐΈ (struct embedding)ɿ ҠৡʹΑΔΠϯλʔϑΣʔεͷ࣮૷ύλʔϯ 1 type Named interface { 2

    Name() string 3 } 4 5 type Animal struct { 6 name string 7 } 8 9 func (a *Animal) Name() string { 10 return a.name 11 } 12 13 type Cat struct { 14 *Animal 15 } ߏ଄ମຒΊࠐΈͰҠৡͯ͠ɺΠϯλʔ ϑΣʔεΛຬͨ͢ύλʔϯɻ ܕʹ֊૚ؔ܎͕ͳ͍ɻΠϯλʔϑΣʔεΛຬ͍ͨͯ͠Δ͔͕ॏཁɻ Golangʹ͸ܧঝ͸ͳ͍ɻ ಗ໊ϑΟʔϧυ*Animalͷϝιου͸ɺ *Catͷॴ༗෺ͷΑ͏ʹΞΫηεͰ͖Δ *Animal͸Name()ϝιουΛ࣋ͭ
  62. ഑෍ํ๏͕୯७

  63. ୯ҰόΠφϦɾΫϩείϯύΠϧͰ഑෍͠΍͍͢

  64. ୯ҰόΠφϦɾΫϩείϯύΠϧͰ഑෍͠΍͍͢ ࣮ߦՄೳϑΝΠϧ͸ɺ୯ҰͷϑΝΠϧʹ·ͱΊΒΕΔɻ ɾجຊతʹ͸ੜ੒͞ΕͨόΠφϦΛ഑෍͢Ε͹ྑ͍ɻ

  65. ୯ҰόΠφϦɾΫϩείϯύΠϧͰ഑෍͠΍͍͢ ࣮ߦՄೳϑΝΠϧ͸ɺ୯ҰͷϑΝΠϧʹ·ͱΊΒΕΔɻ ɾجຊతʹ͸ੜ੒͞ΕͨόΠφϦΛ഑෍͢Ε͹ྑ͍ɻ ؀ڥม਺ͰOSͱΞʔΩςΫνϟΛࢦఆ͢Δ͚ͩɻ

  66. ୯ҰόΠφϦɾΫϩείϯύΠϧͰ഑෍͠΍͍͢ $ GOOS=windows GOARCH=amd64 go build main.go ؀ڥม਺ͰOSͱΞʔΩςΫνϟΛࢦఆ͢Δ͚ͩɻ ྫ͑͹ɺOS X্ͰɺWindowsόΠφϦΛग़ྗ͢Δɻ

    ࣮ߦՄೳϑΝΠϧ͸ɺ୯ҰͷϑΝΠϧʹ·ͱΊΒΕΔɻ ɾجຊతʹ͸ੜ੒͞ΕͨόΠφϦΛ഑෍͢Ε͹ྑ͍ɻ
  67. ୯ҰόΠφϦɾΫϩείϯύΠϧͰ഑෍͠΍͍͢ ྫ͑͹ɺOS X্ͰɺWindowsόΠφϦΛग़ྗ͢Δɻ ࣮ߦՄೳϑΝΠϧ͸ɺ୯ҰͷϑΝΠϧʹ·ͱΊΒΕΔɻ ɾجຊతʹ͸ੜ੒͞ΕͨόΠφϦΛ഑෍͢Ε͹ྑ͍ɻ ͦΕͧΕͷ؀ڥ޲͚ʹΫϩείϯύΠϧͯ͠όΠφϦΛҰͭ഑෍ͰOK ؀ڥม਺ͰOSͱΞʔΩςΫνϟΛࢦఆ͢Δ͚ͩɻ $ GOOS=windows GOARCH=amd64

    go build main.go
  68. Մಡੑ͸େ੾

  69. “No magic”Ͱ͋Δ

  70. “No magic”Ͱ͋Δ ͍ΘΏΔʮࠇຐज़ʯతͳػೳ͸࣮૷͞Εͳ͍

  71. “No magic”Ͱ͋Δ ɾ҉໧తܕม׵ ɾϚΫϩ ɾ҉໧తͳύϥϝʔλʔ ͍ΘΏΔʮࠇຐज़ʯతͳػೳ͸࣮૷͞Εͳ͍

  72. “No magic”Ͱ͋Δ ɾ҉໧తܕม׵ ɾϚΫϩ ɾ҉໧తͳύϥϝʔλʔ ͍ΘΏΔʮࠇຐज़ʯతͳػೳ͸࣮૷͞Εͳ͍ ʮࠇຐज़ʯ͸ڧྗ͚ͩͲɺద੾ʹ࢖͏ͷ͕೉͍͠ɻ

  73. “No magic”Ͱ͋Δ ɾ҉໧తܕม׵ ɾϚΫϩ ɾ҉໧తͳύϥϝʔλʔ ͍ΘΏΔʮࠇຐज़ʯతͳػೳ͸࣮૷͞Εͳ͍ ίʔυ͕ݟͨ໨ͦͷ··ʹ࣮ߦ͞ΕΔ͜ͱ͕ॏࢹ͞ΕΔɻ ʮࠇຐज़ʯ͸ڧྗ͚ͩͲɺద੾ʹ࢖͏ͷ͕೉͍͠ɻ

  74. “No magic”Ͱ͋Δ ɾ҉໧తܕม׵ ɾϚΫϩ ɾ҉໧తͳύϥϝʔλʔ ͍ΘΏΔʮࠇຐज़ʯతͳػೳ͸࣮૷͞Εͳ͍ ίʔυ͕ݟͨ໨ͦͷ··ʹ࣮ߦ͞ΕΔ͜ͱ͕ॏࢹ͞ΕΔɻ ʮࠇຐज़ʯ͸ڧྗ͚ͩͲɺద੾ʹ࢖͏ͷ͕೉͍͠ɻ ෳࡶͳػೳΛͱΓ͜·ͳ͍͜ͱͰݴޠͦͷ΋ͷΛγϯϓϧʹอͭɻ

  75. “No magic”Ͱ͋Δ ɾ҉໧తܕม׵ ɾϚΫϩ ɾ҉໧తͳύϥϝʔλʔ ͍ΘΏΔʮࠇຐज़ʯతͳػೳ͸࣮૷͞Εͳ͍ ίʔυ͕ݟͨ໨ͦͷ··ʹ࣮ߦ͞ΕΔ͜ͱ͕ॏࢹ͞ΕΔɻ ʮࠇຐज़ʯ͸ڧྗ͚ͩͲɺద੾ʹ࢖͏ͷ͕೉͍͠ɻ ෳࡶͳػೳΛͱΓ͜·ͳ͍͜ͱͰݴޠͦͷ΋ͷΛγϯϓϧʹอͭɻ ࠇຐज़͕ೖΔ༨஍͕গͳ͍ͷͰՄಡੑͱ৴པੑ͕ҡ࣋͞Ε΍͍͢

  76. خ͘͠ͳ͍ͱ͜Ζ

  77. خ͘͠ͳ͍ͱ͜Ζɿ
 δΣωϦΫε͕ͳ͍ɾόʔδϣϯݻఆ͕ਏ͍

  78. خ͘͠ͳ͍ͱ͜Ζɿ
 δΣωϦΫε͕ͳ͍ɾόʔδϣϯݻఆ͕ਏ͍ ɾΠϯλʔϑΣʔεͰ·͔ͳ͑Δέʔε΋ଟ͍͕ɺ೉͍͠৔໘΋ɻ ɾӬٱʹ࣮૷͞Εͳ͍Θ͚Ͱ͸ͳ͍͕ɺޓ׵ੑ্͠͹Β͘͸ͳ͍͔΋ʁ ɾந৅౓ͷߴ͍΋ͷΛॻ͘ͷ͸ਏ͍ɻΉ͠Ζॻ͘΂͖Ͱ͸ͳ͍ɻ δΣωϦΫε૬౰ͷ΋ͷ͸ͳ͍

  79. خ͘͠ͳ͍ͱ͜Ζɿ
 δΣωϦΫε͕ͳ͍ɾόʔδϣϯݻఆ͕ਏ͍ ɾݱঢ়ެࣜͰ͸ɺϥΠϒϥϦͷόʔδϣϯΛݻఆ͢Δखஈ͸ͳ͍ɻ ɾgodepͱ͔gopkg.inͱ͔࢖͑͹Ͱ͖Δ͚Ͳɻ ɾGo 1.5Ҏ߱Ͱͪΐͬͱঢ়گมΘΔ͔΋ʁ ɾΠϯλʔϑΣʔεͰ·͔ͳ͑Δέʔε΋ଟ͍͕ɺ೉͍͠৔໘΋ɻ δΣωϦΫε૬౰ͷ΋ͷ͸ͳ͍ ϥΠϒϥϦͷόʔδϣϯͷݻఆ͕೉͍͠ ɾӬٱʹ࣮૷͞Εͳ͍Θ͚Ͱ͸ͳ͍͕ɺޓ׵ੑ্͠͹Β͘͸ͳ͍͔΋ʁ

    ɾந৅౓ͷߴ͍΋ͷΛॻ͘ͷ͸ਏ͍ɻΉ͠Ζॻ͘΂͖Ͱ͸ͳ͍ɻ
  80. Ұ൪େ੾ͳ͜ͱ

  81. Gopher͸͔Θ͍͍

  82. ·ͱΊɿπʔϧͱࢥ૝Ͱ৺ΛແʹͰ͖Δݴޠ ॆ࣮ͨ͠πʔϧ܈ʹΑΔαϙʔτɻ ੩తܕ෇͚ͳμοΫλΠϐϯάͰ໘౗͘͘͞ͳ͍ɻ ࠇຐज़͕ͳ͍ɻݟͨ໨ͦͷ··ʹಈ͘ɻ goίϚϯυʹϏϧυɾςετɾίʔυ੔ܗɾੜ੒ͳͲͷπʔϧ͕ू໿ ίϯύΠϧ࣌ʹܕνΣοΫͯ͠΄͍͚͠Ͳɺؾ࣋ͪ͸--࢖͍Ͱ͍͍ͨ ҉໧తܕม׵ͱ͔ϚΫϩͱ͔ڧྗ͚ͩͲɺͦΕΑΓ͸ಡΈ΍͢͞ॏࢹ