Golang 2013 – Forhistorie – Inspirationer



Golang 2013 – Forhistorie – Inspirationer

0 0


spain2013-golang

Spain 2013: Golang

On Github homburg / spain2013-golang

Golang 2013

#golang

Go v1.1.1

1
2
3
4
5
6
7
8
9
10
11
package main
 
import (
    "fmt"
)
 
func main() {
    hw := "Hello Go!"
    fmt.Println(hw)
}
                        

Forhistorie

  • 2009 - Rob Pike, Ken Thompson; Bell labs
    • System-language
    • Server-language
    • Alternativ til C++ med GC
  • 2013 - Go v1.1.1
    • Google
    • Heroku
    • Mozilla
    • ...

Platforme og arkitekturer

  • amd64, 386, arm
  • OS X 10.6+
  • Linux 2.6.23+
  • Windows 2000+
  • BSD, etc.

Compiler(e)

  • go build
    • Statisk linked executable (portable)
  • gccgo
    • Dynamisk linked til C-kode
    • Brug pointers vha unsafe package

Inspirationer

  • C-familien {...}
  • Imperativt
  • Ikke rigtig OOP
    1
    2
    3
    4
    type Bil struct {
        Color string
        Wheels int
    }

PHP

Ligner lidt

1
2
3
4
// php: function
func doSomething() {
    // ...
}

JavaScript

Funktionel programmering (altså ikke rigtigt)

First class functions

Ingen semikolon

1
2
3
4
5
6
7
x := 42
 
f := (func (arghh) {
    return func() {
        fmt.Println("Value!" + string(arghh))
    }
}(x))

Python

1
2
3
4
5
6
7
8
9
10
11
12
13
package main
// python: module
 
is := []int{1, 22, 74, 23, 34}
 
// python: for x in range(1, 10)
for i := range is {
    fmt.Println(i)
}
 
path.Join("home", "thomas", "code", "go")
// => /home/thomas/code/go
                        

Standard library

golang.org/pkg/

Implementeret i Go og fuld af kodeeksempler. bl.a. printf

  • http-server
  • fcgi-server (php-fpm)
  • jsonrpc
    • codecs
    • json
    • xml
    • gob (binary)
  • unicode
  • bytes/bufio
  • reflection
  • go ast, scanner, parser. Statisk analyse.
  • os - Cross platform fs access
  • testing - http, etc.

Reflection / statisk analyse

gocode giver høj VIM-faktor

autocompletion på variabel-niveau

net/http

Abstraheret request/response

Handlers from type (objekt) eller function

Tools

Batteries included...

$ go ...
  • go fmt - Håndhæver den korrekte formattering
  • go get - Download and install packages from github, google code, etc.
  • go test - Run package tests
  • go list - List installed packages
  • go run - Run go file (#!/usr/bin/gorun)
  • go build - Build go executable
  • go install - Install go package
  • go doc - Produce documentation

Python

Alt er dynamisk: metoder, etc.

Masser af magi: __repr__, __del__, __getitem__, __init__, __le__, etc.

1
2
3
4
5
6
7
8
class Fisk(object):
    def __le__(self, other):
        pass
 
f1 = Fisk()
f2 = Fisk()
print f2 < f1
                    

Goroutines

1
2
3
4
5
6
7
go func () {...}()
 
select {
    case <-myChannel:
    return;
}
                    

Issues

  • Pakke-navne efter VCS-addresse
  • Ingen templating/generics