First impressions of Go

13
First impressions of Go OGAWA Yusaku

Transcript of First impressions of Go

Page 1: First impressions of Go

First impressions of GoOGAWA Yusaku

Page 2: First impressions of Go

About me

● OGAWA Yusaku

● HDE, Inc.

● Newbie gopher

Page 3: First impressions of Go

So good

● Go commands○ go build○ go run○ go fmt○ go test○ go get○ etc.

Page 4: First impressions of Go

So good: go fmt

$ go fmt main.go<Before> <After>

package mainimport "fmt"func main(){ sum:=0 for i:=0;i<10;i++{sum+=i} fmt.Println(sum)}

package main

import "fmt"

func main() {sum := 0for i := 0; i < 10; i++ {

sum += i}fmt.Println(sum)

}

Page 5: First impressions of Go

So good: go test$ lsfoo.go foo_test.go

$ go testPASSok _/path/to/src/foo 0.027s

Page 6: First impressions of Go

Good habit

Page 7: First impressions of Go

Not so good (for me)

● Library○ The standard library

(In genaral, good enough for writing code, but...)

○ Third-party libraries

Page 8: First impressions of Go

Not so good: The standard library

● net/mail (Mail parsing library)http://golang.org/pkg/net/mail/

eml, _ := os.Open("hello.eml")msg, _ := mail.ReadMessage(eml)msg.Header.Get("Subject")

Page 9: First impressions of Go

<Mail>Received: from example.net ([x.x.x.x]) by example.org (foo); Fri, 30 May 2014 00:00:00 +0900 (JST)Received: from example.com ([y.y.y.y]) by example.net (bar); Fri, 30 May 2014 00:00:00 +0900 (JST)Date: Fri, 30 May 2014 00:00:00 +0900From: from <[email protected]>Subject: This is a subject header

Hello

<Output>msg.Header.Get("Subject")=> This is a subject header

msg.Header.Get("Received")=> Received: from example.net ([x.x.x.x]) by example.org (foo); Fri, 30 May 2014 00:00:00 +0900 (JST)

Page 10: First impressions of Go

http://golang.org/src/pkg/net/mail/message.go#L103 103 104 // A Header represents the key-value pairs in a mail message header. 105 type Header map[string][]string 106

Page 11: First impressions of Go

<UTF-8>=?UTF-8?B?SGVsbG8sIEdvbGFuZy4=?==> Hello, Golang.

<ISO-2022-JP>=?ISO-2022-JP?B?GyRCJE8kbSE8GyhCLCBHb2xhbmcu?==> Error: missing word in phrase

http://golang.org/src/pkg/net/mail/message.go#L445 445 charset, enc := strings.ToLower(fields[1]), strings.ToLower(fields[2]) 446 if charset != "iso-8859-1" && charset != "utf-8" { 447 return "", fmt.Errorf("mail: charset not supported: %q", charset) 448 }

Page 12: First impressions of Go

Not so good: Thirt-party librariesThere are too many standards

● e.g. Iconv bindings for Go○ github.com/qiniu/iconv○ github.com/djimenez/iconv-go○ github.com/xushiwei/go-iconv○ github.com/hwch/iconv○ github.com/xuyu/iconv○ github.com/erkl/iconv○ github.com/moovweb/goconv○ github.com/ChaimHong/go-iconv○ github.com/zhigangc/goconv○ github.com/vedranvuk/bindiconv○ github.com/jhiter/goiconv

http://www.xkcd.com/927/

Page 13: First impressions of Go

Thank you