goをえらんだ理由
DESCRIPTION
数あるプログラミング言語から、社内用の開発ツールとして Go を選んだ理由について書きました。 NSEG #50 (2014/4/19) 発表資料。 補足:Windows 2000のサポートは2014/6/18にリリースされたGo 1.3で削除されました。http://golang.org/doc/go1.3#win2000TRANSCRIPT
![Page 1: Goをえらんだ理由](https://reader033.vdocuments.pub/reader033/viewer/2022042815/55858fb8d8b42abc7b8b4691/html5/thumbnails/1.jpg)
Goをえらんだ理由
ながぬまたつみ2014/4/19 NSEG #50
![Page 2: Goをえらんだ理由](https://reader033.vdocuments.pub/reader033/viewer/2022042815/55858fb8d8b42abc7b8b4691/html5/thumbnails/2.jpg)
自己紹介
ながぬまたつみ
上田市の電子機器メーカーに勤務
![Page 3: Goをえらんだ理由](https://reader033.vdocuments.pub/reader033/viewer/2022042815/55858fb8d8b42abc7b8b4691/html5/thumbnails/3.jpg)
Go とは
オープンソースのプログラミング言語
![Page 4: Goをえらんだ理由](https://reader033.vdocuments.pub/reader033/viewer/2022042815/55858fb8d8b42abc7b8b4691/html5/thumbnails/4.jpg)
なぜ Go なのか
社内で使うツールの開発言語
でもプログラミング言語は他にもたくさんある
なぜ Go なのか
![Page 5: Goをえらんだ理由](https://reader033.vdocuments.pub/reader033/viewer/2022042815/55858fb8d8b42abc7b8b4691/html5/thumbnails/5.jpg)
新しい機能を備えている
![Page 6: Goをえらんだ理由](https://reader033.vdocuments.pub/reader033/viewer/2022042815/55858fb8d8b42abc7b8b4691/html5/thumbnails/6.jpg)
Go 言語&開発環境
2009年登場で、新しい機能をサポート
● tar , zip , zlib , gzip , bzip2● DES , AES , SHA1 , SHA256 , SHA512● PE , ELF , DWARF● BASE64 , ASN.1 , JSON , XML , PEM● HTTP , SMTPパッケージシステム ビルドシステム
ドキュメントシステム テストフレームワーク
Google App Engine Experimental!
![Page 7: Goをえらんだ理由](https://reader033.vdocuments.pub/reader033/viewer/2022042815/55858fb8d8b42abc7b8b4691/html5/thumbnails/7.jpg)
これだけなら他にもありそう
しかし決定的な違いがある
![Page 8: Goをえらんだ理由](https://reader033.vdocuments.pub/reader033/viewer/2022042815/55858fb8d8b42abc7b8b4691/html5/thumbnails/8.jpg)
http://golang.org/doc/install
![Page 9: Goをえらんだ理由](https://reader033.vdocuments.pub/reader033/viewer/2022042815/55858fb8d8b42abc7b8b4691/html5/thumbnails/9.jpg)
http://golang.org/doc/install
ココ
![Page 10: Goをえらんだ理由](https://reader033.vdocuments.pub/reader033/viewer/2022042815/55858fb8d8b42abc7b8b4691/html5/thumbnails/10.jpg)
![Page 11: Goをえらんだ理由](https://reader033.vdocuments.pub/reader033/viewer/2022042815/55858fb8d8b42abc7b8b4691/html5/thumbnails/11.jpg)
Windows 2000
![Page 12: Goをえらんだ理由](https://reader033.vdocuments.pub/reader033/viewer/2022042815/55858fb8d8b42abc7b8b4691/html5/thumbnails/12.jpg)
「Windows 2000 SP3という環境でないと、不具合が発生しな
いことを再確認しました。」(2007 バグトラッカーのコメント)
「起動時にエラーが出ました。PCが貧弱すぎるのかもしれませ
ん。CPU:Celeron 433MHz OS:Win2000 SP4」(2011 検証者からのメール)
「Windows 2000 で動作させるため、古いバージョンのライブラ
リを適用した。」(2013 リポジトリのコミットログ)
※このスライドはフィクションです。実際の人物や団体等とは一切関係ありません。
![Page 13: Goをえらんだ理由](https://reader033.vdocuments.pub/reader033/viewer/2022042815/55858fb8d8b42abc7b8b4691/html5/thumbnails/13.jpg)
古い環境でも動く
![Page 14: Goをえらんだ理由](https://reader033.vdocuments.pub/reader033/viewer/2022042815/55858fb8d8b42abc7b8b4691/html5/thumbnails/14.jpg)
クロスコンパイルやデプロイが簡単
![Page 15: Goをえらんだ理由](https://reader033.vdocuments.pub/reader033/viewer/2022042815/55858fb8d8b42abc7b8b4691/html5/thumbnails/15.jpg)
クロスコンパイルが簡単
Windows 32-bit環境用のバイナリを作る
$ GOOS=windows GOARCH=386 go build
Linux 64-bit環境用のバイナリを作る
$ GOOS=linux GOARCH=amd64 go build
![Page 16: Goをえらんだ理由](https://reader033.vdocuments.pub/reader033/viewer/2022042815/55858fb8d8b42abc7b8b4691/html5/thumbnails/16.jpg)
デプロイが簡単
Dockerの場合
$ wget https://get.docker.io/builds/Linux/x86_64/docker-latest -O docker$ chmod +x docker
http://docs.docker.io/installation/binaries/
![Page 17: Goをえらんだ理由](https://reader033.vdocuments.pub/reader033/viewer/2022042815/55858fb8d8b42abc7b8b4691/html5/thumbnails/17.jpg)
なぜ Go なのか (まとめ)
新しい機能を備えている
古い環境でも動く
クロスコンパイルやデプロイが簡単
![Page 18: Goをえらんだ理由](https://reader033.vdocuments.pub/reader033/viewer/2022042815/55858fb8d8b42abc7b8b4691/html5/thumbnails/18.jpg)
以上
本日言いたかったことは、だいたい言いました。
![Page 19: Goをえらんだ理由](https://reader033.vdocuments.pub/reader033/viewer/2022042815/55858fb8d8b42abc7b8b4691/html5/thumbnails/19.jpg)
言語についても少しだけ
複数値
Goroutine
エラー処理
![Page 20: Goをえらんだ理由](https://reader033.vdocuments.pub/reader033/viewer/2022042815/55858fb8d8b42abc7b8b4691/html5/thumbnails/20.jpg)
Hello World
// HelloWorld.go
package main
import ”fmt”
func main() {
fmt.Println(”Hello, world!”)
}
![Page 21: Goをえらんだ理由](https://reader033.vdocuments.pub/reader033/viewer/2022042815/55858fb8d8b42abc7b8b4691/html5/thumbnails/21.jpg)
複数値
var a int
// var a int = 0
// a := 0
var b int
a, b = 1, 2
a, b = b, a
file, err := os.Open(”file.txt”)
![Page 22: Goをえらんだ理由](https://reader033.vdocuments.pub/reader033/viewer/2022042815/55858fb8d8b42abc7b8b4691/html5/thumbnails/22.jpg)
Goroutine
func process() {
}
go process()
// go func() {}
![Page 23: Goをえらんだ理由](https://reader033.vdocuments.pub/reader033/viewer/2022042815/55858fb8d8b42abc7b8b4691/html5/thumbnails/23.jpg)
Goroutine
func process(ch chan<- int) {
ch <- 1
ch <- 2
ch <- 3
}
c := make(chan int)go process(c)
fmt.Printf(
”out=%d %d %d\n”, <- c, <- c, <- c)
![Page 24: Goをえらんだ理由](https://reader033.vdocuments.pub/reader033/viewer/2022042815/55858fb8d8b42abc7b8b4691/html5/thumbnails/24.jpg)
エラー処理
file, err := os.Open(”file.txt”)
if err != nil {
panic(err) // どうしようもないとき
}
defer file.Close()
// Open
func Open(name string) (file *File, err error)
// error
type error interface {
Error() string
}
![Page 25: Goをえらんだ理由](https://reader033.vdocuments.pub/reader033/viewer/2022042815/55858fb8d8b42abc7b8b4691/html5/thumbnails/25.jpg)
文法について感想
強い静的型付け & ダックタイピング
書きやすいエラー処理
短く書けて、あとからも読みやすい