Diese Präsentation wurde erfolgreich gemeldet.
Die SlideShare-Präsentation wird heruntergeladen. ×

Trivadis TechEvent 2016 Go - The Cloud Programming Language by Andija Sisko

Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Nächste SlideShare
Go lang introduction
Go lang introduction
Wird geladen in …3
×

Hier ansehen

1 von 33 Anzeige
Anzeige

Weitere Verwandte Inhalte

Diashows für Sie (20)

Anzeige

Ähnlich wie Trivadis TechEvent 2016 Go - The Cloud Programming Language by Andija Sisko (20)

Weitere von Trivadis (20)

Anzeige

Aktuellste (20)

Trivadis TechEvent 2016 Go - The Cloud Programming Language by Andija Sisko

  1. 1. BASLE BERN BRUGG DÜSSELDORF FRANKFURT A.M. FREIBURG I.BR. GENEVA HAMBURG COPENHAGEN LAUSANNE MUNICH STUTTGART VIENNA ZURICH GO The Cloud Programming Language – An Introduction and Feature Overview Andrija Sisko
  2. 2. Agenda Go - The Cloud Programming Language - An Introduction and Feature Overview2 19.09.2016 1. Background 2. Features
  3. 3. Go - The Cloud Programming Language - An Introduction and Feature Overview3 19.09.2016 Background
  4. 4. Brief Histroy Go - The Cloud Programming Language - An Introduction and Feature Overview4 19.09.2016 Started at Google as an answer to some of the problems seen when developing software infrastructure at Google Go's lead developers at Google were Robert Griesemer (Google's V8 JavaScript engine), Rob Pike (UTF-8, with Ken Thompson), and Ken Thompson (1st implementer of Unix, with Dennis Ritchie) Discussions start in late 2007 First draft of specification in March 2008 Open sourced to the public in 2009 Go 1.0, 2012, language specification, standard libraries, and custom tools Go 1.5, 2015, compiler and runtime written in Go Go 1.7.1 (latest), 07.09.2016
  5. 5. Origins (1) Go - The Cloud Programming Language - An Introduction and Feature Overview5 19.09.2016 The Algol family of programming languages – Block structure – Nested and recursive functions and procedures – Type declarations – Static typing Algol60 successors: C, Pascal Pascal successors: Modula, Modula-2, Oberon, Object Oberon, Oberon-2
  6. 6. Origins (2) Go - The Cloud Programming Language - An Introduction and Feature Overview6 19.09.2016 C: statement and expression syntax Pascal: declaration syntax Modula 2, Oberon 2: packages CSP, Occam, Newsqueak, Limbo, Alef: concurrency BCPL: the semicolon rule Smalltalk: methods Newsqueak: <-, := APL: iota
  7. 7. Origins (3) Go - The Cloud Programming Language - An Introduction and Feature Overview7 19.09.2016 Tree node lookup in Oberon-2 MODULE Trees; IMPORT Texts, Oberon; TYPE Tree* = POINTER TO Node; (* star denotes export, not pointer! *) Node* = RECORD name-: POINTER TO ARRAY OF CHAR; (* minus denotes read-only export *) left, right: Tree END; PROCEDURE (t: Tree) Lookup* (name: ARRAY OF CHAR): Tree; VAR p: Tree; BEGIN p := t; WHILE (p # NIL) & (name # p.name^) DO IF name < p.name^ THEN p := p.left ELSE p := p.right END END; RETURN p END Lookup; ... package trees import ( "fmt"; "runtime" ) type ( Tree *Node Node struct { name string left, right Tree }) func (t *Node) Lookup(name string) Tree { var p Tree p = t for p != nil && name != p.name { if name < p.name { p = p.left } else { p = p.right } } return p } ... Tree node lookup in Go Source: The Evolution of Go; GopherCon 2015 Keynote - July 9, 2015; Robert Griesemer; Google, Inc.
  8. 8. Modern Programming Language Design? Go - The Cloud Programming Language - An Introduction and Feature Overview8 19.09.2016  Object Oriented  Functional  Generics  Memory Management (Garbage Collection)  Concurrency
  9. 9. Go Design Goals (1)  Simplicity Go - The Cloud Programming Language - An Introduction and Feature Overview9 19.09.2016 Clean procedural language designed for scalable cloud software. Composable distinct elements, including: – concrete data types – functions and methods – interfaces – packages – concurrency Good tools, fast builds. All the pieces feel simple in practice. Keywords: Go ~25, Java ~50, C# ~80 Source: Simplicity is Complicated; dotGo 09.11.2015; Rob Pike; Google Inc.
  10. 10. Go Design Goals (2)  Maintainability Go - The Cloud Programming Language - An Introduction and Feature Overview10 19.09.2016 import scalaz._ import scalaz.std.list._ import scalaz.syntax.monad._ import scalaz.syntax.monoid._ import scalaz.syntax.traverse.{ToFunctorOps => _, _} class Foo[F[+_] : Monad, A, B](val execute: Foo.Request[A] => F[B], val joins: Foo.Request[A] => B => List[Foo.Request[A]])(implicit J: Foo.Join[A, B]) { def bar: Foo[({type l[+a]=WriterT[F, Log[A, B], a]})#l, A, B] = { type TraceW[FF[+_], +AA] = WriterT[FF, Log[A, B], AA] def execute(request: Request[A]): WriterT[F, Log[A, B], B] = self.execute(request).liftM[TraceW] :++>> (repr => List(request -> request.response(repr, self.joins(request)(repr)))) ----- REDACTED ------- Source: Moving a team from Scala to Golang; http://jimplush.com/talk/2015/12/19/moving-a-team-from-scala-to-golang/
  11. 11. Go Design Goals (3)  Readability Go - The Cloud Programming Language - An Introduction and Feature Overview11 19.09.2016 From Docker principles (https://github.com/docker/docker/blob/master/project/PRINCIPLES.md) – 50 lines of straightforward, readable code is better than 10 lines of magic that nobody can understand.
  12. 12. Go Characteristics Go - The Cloud Programming Language - An Introduction and Feature Overview12 19.09.2016 Procedural language Statically typed Syntax similar to C (parentheses, no semicolons), with the structure of Oberon-2 Compiles to native code (no VM)  fast execution No classes, but structs with methods Interfaces No implementation inheritance (composition over inheritance) Functions are first class citizens Functions can return multiple values Has closures Pointers, but not pointer arithmetic Built-in concurrency primitives: Goroutines and Channels
  13. 13. Go - The Cloud Programming Language - An Introduction and Feature Overview13 19.09.2016 Features
  14. 14. Fast Compiler Go - The Cloud Programming Language - An Introduction and Feature Overview14 19.09.2016 Reason: Dependency analysis. – Go provides a model for software construction that makes dependency analysis easy and avoids much of the overhead of C-style include files and libraries. (Go FAQ) – Builds in less than 20 seconds on a Source: https://www.openhub.net/p/docker
  15. 15. Compilation and Deployment Go - The Cloud Programming Language - An Introduction and Feature Overview15 19.09.2016 Go usually (if pure Go and not linking code from other languages) compiles to one single statically linked, native executable. The deployment of a Go program can be done by simply copy the executable.
  16. 16. Package System (1) Go - The Cloud Programming Language - An Introduction and Feature Overview16 19.09.2016 All Go source is part of a package. Every file begins with a package statement. The imported package path is a simple string. Programs start in package main. package main import "fmt" func main() { fmt.Println("Hello, world!") }
  17. 17. Package System (2) Go - The Cloud Programming Language - An Introduction and Feature Overview17 19.09.2016 Function Println is exported  other packages can call it. Starts with a upper case letter. Function newPrinter in unexported  can only be used inside of the fmt package. // Package fmt implements formatted I/O. package fmt // Println formats using the default formats for its // operands and writes to standard output. func Println(a ...interface{}) (n int, err error) { ... } func newPrinter() *pp { ... }
  18. 18. Testing Go Packages Go - The Cloud Programming Language - An Introduction and Feature Overview18 19.09.2016 Package testing provides support for automated testing of Go packages. Tests are distinguished by file name. Test files end in _test.go. package fmt import "testing" var fmtTests = []fmtTest{ {"%d", 12345, "12345"}, {"%v", 12345, "12345"}, {"%t", true, "true"}, } func TestSprintf(t *testing.T) { for _, tt := range fmtTests { if s := Sprintf(tt.fmt, tt.val); s != tt.out { t.Errorf("...") } } }
  19. 19. Code Organization Go - The Cloud Programming Language - An Introduction and Feature Overview19 19.09.2016 Go code is kept in a workspace. The GOPATH environment variable tells the Go tool where your workspace is located. Using a file layout for builds means no configuration: No makefile, no build.xml, no … Everyone in the community uses the same layout. This makes it easier to share code. $GOPATH/ src/ github.com/user/repo/ mypkg/ mysrc1.go mysrc2.go cmd/mycmd/ main.go bin/ mycmd
  20. 20. Remote Packages Go - The Cloud Programming Language - An Introduction and Feature Overview20 19.09.2016 The import path can refer to remote repositories. $ go get github.com/4ad/doozer // Shell command to fetch package import "github.com/4ad/doozer" // Doozer client's import statement var client doozer.Conn // Client's use of package $ go get -u all // Updates all packages under the $GOPATH
  21. 21. Error Handling Go - The Cloud Programming Language - An Introduction and Feature Overview21 19.09.2016 Go has no exceptions. Errors are indicated with the built-in Error type. The idiomatic way of error handling in go is to check for errors right after the function call. f, err := os.Open("filename.ext") if err != nil { log.Fatal(err) } // do something with the open *File f
  22. 22. Defer Statement Go - The Cloud Programming Language - An Introduction and Feature Overview22 19.09.2016 A defer statement pushes a function call onto a list. The list of saved calls is executed after the surrounding function returns. Can be used to put acquisition and cleanup of a resource side by side func CopyFile(dstName, srcName string) (written int64, err error) { src, err := os.Open(srcName) if err != nil { return } defer src.Close() dst, err := os.Create(dstName) if err != nil { return } defer dst.Close() return io.Copy(dst, src) }
  23. 23. Methods on Structs Go - The Cloud Programming Language - An Introduction and Feature Overview23 19.09.2016 package main import "fmt" type Rectangle struct { length, width int } func (r Rectangle) Area() int { return r.length * r.width } func main() { r1 := Rectangle{4, 3} fmt.Println("Rectangle is: ", r1) fmt.Println("Rectangle area is: ", r1.Area()) }
  24. 24. Tools Go - The Cloud Programming Language - An Introduction and Feature Overview24 19.09.2016 go : build, clean, run, test, install, get, … . go vet : Go linter for analysing Go code and finding common mistakes. golint : Checks the code for style violations. go tool cover : Reports code coverage (untested code). godoc : Extracts and generates documentation for Go programs. gofmt : Formats the code according to the only acceptable way of formatting it. and many more …
  25. 25. Interfaces Go - The Cloud Programming Language - An Introduction and Feature Overview25 19.09.2016 Interfaces are named collections of method signatures. Whether or not a type satisfies an interface is determined automatically. Not implements keyword. Any type that defines this method is said to satisfy the Stringer interface type Stringer interface { String() string }
  26. 26. Concurrency (1) Go - The Cloud Programming Language - An Introduction and Feature Overview26 19.09.2016 Based on the work/paper “Communicating Sequential Processes (CSP)” by Tony Hoare (1978). Based on message-passing (CSP, Actor Model), instead of shared memory.
  27. 27. Concurrency (2) - Goroutines Go - The Cloud Programming Language - An Introduction and Feature Overview27 19.09.2016 A goroutine is a function that is capable of running concurrently with other functions. Goroutines are lightweight. We can easily create thousands of them. Use the keyword «go» to start a new goroutine. package main import ( "fmt" "time" ) func say(s string) { for i := 0; i < 5; i++ { time.Sleep(100 * time.Millisecond) fmt.Println(s) } } func main() { go say("world") say("hello") }
  28. 28. Concurrency (3) - Channels Go - The Cloud Programming Language - An Introduction and Feature Overview28 19.09.2016 With channels we can pass safely data between goroutines. Channels are by default synchronous  blocking. Buffered channels are asynchronous  non blocking. my_channel := make(chan int) //within some goroutine - to put a value on the channel my_channel <- 5 //within some other goroutine - to take a value off the channel var my_recvd_value int my_recvd_value = <- my_channel
  29. 29. Who Uses Go Go - The Cloud Programming Language - An Introduction and Feature Overview30 19.09.2016 GopherCon 2016 Sponsors
  30. 30. Go - The Cloud Programming Language - An Introduction and Feature Overview31 19.09.2016 - https://golang.org/ - https://github.com/golang - …
  31. 31. List of Sources Go - The Cloud Programming Language - An Introduction and Feature Overview32 19.09.2016 https://github.com/a8m/go-lang-cheat-sheet https://talks.golang.org/2015/gophercon-goevolution.slide#1 https://talks.golang.org/2014/hellogophers.slide#1 http://jimplush.com/talk/2015/12/19/moving-a-team-from-scala-to-golang/ http://golangtutorials.blogspot.ch/ https://gobyexample.com/ http://dave.cheney.net/ https://www.golang-book.com/books/intro http://arild.github.io/csp-presentation/#1 https://en.wikipedia.org/wiki/Communicating_sequential_processes https://en.wikipedia.org/wiki/Go_(programming_language) https://www.youtube.com/watch?v=uQgWP7zM6mU http://www.javaworld.com/article/2929811/scripting-jvm-languages/whats-the-go-language-really-good-for.html
  32. 32. Andrija Sisko Senior Consultant ZH-AD Tel. +41 58 459 53 01 andrija.sisko@trivadis.com 19.09.2016 Go - The Cloud Programming Language - An Introduction and Feature Overview33
  33. 33. Session Feedback – now Go - The Cloud Programming Language - An Introduction and Feature Overview34 19.09.2016 Please use the Trivadis Events mobile app to give feedback on each session Use "My schedule" if you have registered for a session Otherwise use "Agenda" and the search function If the mobile app does not work (or if you have a Windows smartphone), use your smartphone browser – URL: http://trivadis.quickmobileplatform.eu/ – User name: <your_loginname> (such as “svv”) – Password: sent by e-mail...

×