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

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

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

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

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

Tomoya Kose

June 22, 2015
Tweet

More Decks by Tomoya Kose

Other Decks in Programming

Transcript

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

    View full-size slide

  2. ͓·͑ɺͩΕΑɻ

    View full-size slide

  3. ͓·͑ɺͩΕΑɻ

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  8. Golangॻ͍ͯ·͔͢ʁ

    View full-size slide

  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/

    View full-size slide

  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/

    View full-size slide

  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/

    View full-size slide

  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/

    View full-size slide

  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/

    View full-size slide

  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/
    γϯϓϧͰ৴པੑͷ͋Δޮ཰ͷྑ͍ιϑτ΢ΣΞͷߏஙΛָʹʂ

    View full-size slide

  15. ͳͥॻ͘ͷ͔ɿ
    ৺Λແʹͯ͠ॻ͘ͷʹௐ౓ྑ͍͔Β

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  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
    ίϯύΠϧɾ࣮ߦΛ͓͜ͳ͏ɻ
    ɾίϯύΠϧ͸ߴ଎
    ɾ͍ΘΏΔ--తͳؾ࣋ͪͰ࣮ߦ

    View full-size slide

  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!

    View full-size slide

  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

    View full-size slide

  32. HPGNUίʔυΛ੔͑Δ

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  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
    ɾελΠϧͷ౷Ұͱ͍͏ ॏཁ͚ͩͲ
    ෆໟͳٞ࿦͕ى͖ͳ͍ɻ
    ɾίʔυΛॻ͘͜ͱʹूதͰ͖Δɻอଘ࣌ʹࣗಈͰϑΥʔϚοτɻ

    View full-size slide

  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
    ɾελΠϧͷ౷Ұͱ͍͏ ॏཁ͚ͩͲ
    ෆໟͳٞ࿦͕ى͖ͳ͍ɻ
    ɾίʔυΛॻ͘͜ͱʹूதͰ͖Δɻอଘ࣌ʹࣗಈͰϑΥʔϚοτɻ

    View full-size slide

  39. HPHFUύοέʔδΛऔಘͯ͠Πϯετʔϧ

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  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૬౰ϑΝΠϧ΍ґଘؔ܎Λఆٛ͢ΔϑΝΠϧ͕ଘࡏ͠ͳ͍ɻ

    View full-size slide

  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૬౰ϑΝΠϧ΍ґଘؔ܎Λఆٛ͢ΔϑΝΠϧ͕ଘࡏ͠ͳ͍ɻ

    View full-size slide

  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૬౰ϑΝΠϧ΍ґଘؔ܎Λఆٛ͢ΔϑΝΠϧ͕ଘࡏ͠ͳ͍ɻ

    View full-size slide

  45. ܕγεςϜ͕୯७
    ܕʹ֊૚ؔ܎͕ͳ͍

    View full-size slide

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

    View full-size slide

  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 }
    ߏ଄ମͷΠϯελϯε͔Βυοτ෇͖Ͱϝιουݺͼग़͕͠Մೳɻ

    View full-size slide

  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 }
    ߏ଄ମͱϑΟʔϧυ
    ߏ଄ମͷΠϯελϯε͔Βυοτ෇͖Ͱϝιουݺͼग़͕͠Մೳɻ

    View full-size slide

  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 }
    ߏ଄ମͱϑΟʔϧυ
    ߏ଄ମ͸ϝιουΛ࣋ͭ
    ߏ଄ମͷΠϯελϯε͔Βυοτ෇͖Ͱϝιουݺͼग़͕͠Մೳɻ

    View full-size slide

  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Ͱੜ੒ɾॳظԽ
    ߏ଄ମͷΠϯελϯε͔Βυοτ෇͖Ͱϝιουݺͼग़͕͠Մೳɻ

    View full-size slide

  51. ΠϯλʔϑΣʔε (interface)ɿ
    ϝιουఆٛͷू·Γ

    View full-size slide

  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 }
    ΠϯλʔϑΣʔεͰϝιουͷγάωνϟΛఆٛ͢Δɻ

    View full-size slide

  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 }
    ΠϯλʔϑΣʔε͸ϝιου܈Λఆٛ
    ΠϯλʔϑΣʔεͰϝιουͷγάωνϟΛఆٛ͢Δɻ

    View full-size slide

  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()ϝιουΛ࣋ͭ
    ΠϯλʔϑΣʔεͰϝιουͷγάωνϟΛఆٛ͢Δɻ

    View full-size slide

  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Λຬ͍ͨͯ͠Δ
    ΠϯλʔϑΣʔεͰϝιουͷγάωνϟΛఆٛ͢Δɻ

    View full-size slide

  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Λຬ͍ͨͯ͠Δ

    View full-size slide

  57. ߏ଄ମຒΊࠐΈ (struct embedding)ɿ
    ҠৡʹΑΔΠϯλʔϑΣʔεͷ࣮૷ύλʔϯ

    View full-size slide

  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ʹ͸ܧঝ͸ͳ͍ɻ
    ߏ଄ମຒΊࠐΈͰҠৡͯ͠ɺΠϯλʔ
    ϑΣʔεΛຬͨ͢ύλʔϯɻ

    View full-size slide

  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ʹ͸ܧঝ͸ͳ͍ɻ

    View full-size slide

  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()ϝιουΛ࣋ͭ

    View full-size slide

  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()ϝιουΛ࣋ͭ

    View full-size slide

  62. ഑෍ํ๏͕୯७

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  68. Մಡੑ͸େ੾

    View full-size slide

  69. “No magic”Ͱ͋Δ

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  76. خ͘͠ͳ͍ͱ͜Ζ

    View full-size slide

  77. خ͘͠ͳ͍ͱ͜Ζɿ

    δΣωϦΫε͕ͳ͍ɾόʔδϣϯݻఆ͕ਏ͍

    View full-size slide

  78. خ͘͠ͳ͍ͱ͜Ζɿ

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

    View full-size slide

  79. خ͘͠ͳ͍ͱ͜Ζɿ

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

    View full-size slide

  80. Ұ൪େ੾ͳ͜ͱ

    View full-size slide

  81. Gopher͸͔Θ͍͍

    View full-size slide

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

    View full-size slide