28
Good artists borrow, great artists steal. — Pablo Picasso The Go Programming Language Frank Müller

Google Go - Good artists borrow, great artists steal

Embed Size (px)

Citation preview

Page 1: Google Go - Good artists borrow, great artists steal

Good artists borrow, great artists steal.

— Pablo Picasso

The Go Programming LanguageFrank Müller

Page 2: Google Go - Good artists borrow, great artists steal

Jan Feb Mär Apr Mai Jun Jul Aug Sep Okt Nov Dez

0 0 0 0 0 0 0 0 0 0 0

13

TIOBE Index Platz 13Sprache des Jahres 2009

Steile Karriere

Page 3: Google Go - Good artists borrow, great artists steal

Zielsetzung: schnelle, einfache und moderne

Systemsprache

Veröffentlichung

November 2009

Design Mitte 2008 fertig,Implementierung beginnt

Ende 2007 Start durch

Robert Griesemer, Rob Pike

und Ken Thompson

Historie und Motivation

Page 4: Google Go - Good artists borrow, great artists steal

Hohe Geschwindigkeit

In etwaGeschwindigkeitC

Page 5: Google Go - Good artists borrow, great artists steal

10Sekunden584 Dateien4,1 MB

Compiling der Go Packages

Page 6: Google Go - Good artists borrow, great artists steal

Einfachheit

Page 7: Google Go - Good artists borrow, great artists steal

Organisation in Paketen

Page 8: Google Go - Good artists borrow, great artists steal

Export durch Großschreibung

Page 9: Google Go - Good artists borrow, great artists steal

Typenvielfalt

Page 10: Google Go - Good artists borrow, great artists steal

Wahrheitswerte Maps Referenzen

Zahlen von 8 bis 64 Bit

Arrays und Slices Zeichenketten

Funktionen Kanäle

Strukturen

Schnittstellen

Standardtypen

Page 11: Google Go - Good artists borrow, great artists steal

Implizite Variablendeklaration

Page 12: Google Go - Good artists borrow, great artists steal

Vielfältige und mächtige Schleifen

Page 13: Google Go - Good artists borrow, great artists steal

Klare Strukturen

Page 14: Google Go - Good artists borrow, great artists steal

MyType

Size

Open

Close

IsOpen

String

Typen und Methoden

Page 15: Google Go - Good artists borrow, great artists steal

Typen und Methoden

type Door struct { ... }

func NewDoor(width, height float64) *Door { ... }

func (d *Door) Open() { ... }

func (d *Door) Close() { ... }

func (d *Door) IsOpen() bool { ... }

func (d *Door) Size() (float64, float64) { ... }

func (d *Door) String() string { ... }

Page 16: Google Go - Good artists borrow, great artists steal

Schnittstellen zur Abstraktion

Page 17: Google Go - Good artists borrow, great artists steal

Schnittstellen

type Foo int64type Bar struct { id string }

type TypePrintable interface {PrintType() string

}

func (f Foo) PrintType() string {return “I‘m a Foo (int64).“

}

func (b Bar) PrintType() string {return “I‘m a Bar (struct).“

}

Page 18: Google Go - Good artists borrow, great artists steal

Nebenläufigkeit

Page 19: Google Go - Good artists borrow, great artists steal

Beispiel (Teil 1)

package event

type Event interface { ... }

type Handler interface {Id()Handle(evt Event)

}

type Manager struct {subscribers   map[string]HandlersubscribeChan chan HandlereventChan     chan EventstopChan      chan bool

}

Page 20: Google Go - Good artists borrow, great artists steal

Beispiel (Teil 2)

func NewManager() *Manager {sub := make(map[string]Handler)subc := make(chan Handler)evtc := make(chan Event)stpc := make(chan bool)

mngr := &Manager{sub, subc, evtc, stpc}

go mngr.server()

return mngr}

Page 21: Google Go - Good artists borrow, great artists steal

Beispiel (Teil 3)

func (m *Manager) Subscribe(h Handler) {m.subscribeChan <- h

}

func (m *Manager) Raise(e Event) {m.eventChan <- e

}

func (m *Manager) Stop() {m.stopChan <- true

}

Page 22: Google Go - Good artists borrow, great artists steal

Beispiel (Teil 4)

func (m *Manager) server() {for {

select {case h := <-subscribeChan:

m.subscribers[h.Id()] = hcase e := <-eventChan:

for _, h := range m.subscribers {go h.Handle(e)

}case <-stopChan:

return}

}}

Page 23: Google Go - Good artists borrow, great artists steal

Speicherverwaltung

Page 24: Google Go - Good artists borrow, great artists steal

Umfangreiche Bibliothek

Page 25: Google Go - Good artists borrow, great artists steal

Hilfreiche Werkzeuge

gofmt

godoc

gotest profmake

Page 26: Google Go - Good artists borrow, great artists steal

Fazit und Ausblick

Page 27: Google Go - Good artists borrow, great artists steal

Nahe an dynamischen Sprachen

Sehr hohe Produktivität

Einfache Erlernbarkeit

Mächtige

Nebenläufigkeit

erfordert Umdenken

Erfahrungen

Page 28: Google Go - Good artists borrow, great artists steal

Performanz / Spaß / Technologie