Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Go - Why I Fell for it...

Go - Why I Fell for it...

Technologieplauscherl Linz invited me to do a talk about why I started to use and like Go. Here is my presentation. The source can be found on GitHub at https://github.com/rstropek/golang-samples/tree/master/hello-go.

Rainer Stropek

August 29, 2019
Tweet

More Decks by Rainer Stropek

Other Decks in Technology

Transcript

  1. Why? Docker written in Go 13th most popular dev tech

    in Stackoverflow Survey 2019 In front of e.g. Swift, Kotlin, and Dart 9th most loved dev tech in Stackoverflow Survey 2019 Right in front of C# Compiled to native code No dependencies, just a single file WASM support That raised my interest…
  2. Basic Philosophy Keep code simple C# has >100 keywords, Go

    has 25 Don’t be too clever “If you must read the rest of this document to understand the behavior of your program, you are being too clever. Don't be clever.” (docs) Keep code consistent „The output of the current gofmt is what your code should look like, no ifs or buts.” (GitHub) Just because it is young? Go came out late 2009, version 2 just in design phase No, it is in the language‘s genes
  3. Language Design Complexity Features Advantages vs. added complexity Open discussion

    process Experience and learning process Relatively slow
  4. Limitations No classes No generics No try/catch No binary-only packages

    ++ is a statement, not an expression Seriously??
  5. So what? Avoid writing overly smart code Easy to read,

    easy to maintain Improve where it makes sense Don’t be too fast Avoid syntactic sugar Made for Microservices & DevOps Sweetspot Web Apps/APIs Very well suited for container-based workloads Code maintainable on the long run
  6. Start a Module # Initialize current folder as a module

    go mod init github.com/rstropek/golang-samples/hello-go/modules # Look at go.mod # Add sample code to main.go: # Snippet: go, 01-module go run . # Look at go.mod again # Show folder C:\Users\r.stropek\go\pkg\mod\github.com\mbndr Old: GOPATH New: Module System Started in Go 1.11 Will be default in Go 1.13 Built from sources No binary-only packages Dependencies loaded from SCM Use go plugins for modularity https://blog.golang.org/using-go-modules
  7. Compile # Build executable go build modules.exe # Cross-compile to

    Linux set GOARCH=amd64 set GOOS=linux go build bash ./modules # Cross-compile to WASM set GOOS=js set GOARCH=wasm go build -o modules.wasm Compile into single executable Cross-compilation Including WASM https://github.com/golang/go/wiki/WebAssembly
  8. Dockerfile # Add sample Dockerfile main.go: # Snippets: go, 02-Dockerfile

    go, 03-dockerignore # Build image based on Alpine docker build -t hello-go . docker run -t --rm hello-go # Check image size docker images hello-go # Switch to „FROM scratch“ (no RUN) and build/run again # Check image size docker images hello-go Runs very well in containers Small images
  9. Demo Structs, Interfaces Snippets 03-structs 04-json-struct 05-json-print 06-functions 06-functions-call 07-interface

    07-interface-use 08-embedded-struct 09-embedded-struct-use https://play.golang.org/p/37kbcROPsZz
  10. Saves the day. Technologieplauscherl Q&A Rainer Stropek software architects gmbh

    [email protected] http://www.timecockpit.com @rstropek Thank your for coming! Mail Web Twitter