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

Why Learn Go

Avatar for aarti aarti
February 13, 2017

Why Learn Go

Exploring Go, the language, the ecosystem, the community.

Avatar for aarti

aarti

February 13, 2017

More Decks by aarti

Other Decks in Technology

Transcript

  1. About Me Aarti Parikh Sr. Software Engineer, 10+ years, mostly

    backend engineering Have shipped production code with Java, Ruby, JavaScript and Go. Strong Interest in Computer languages Have been writing in Go for a year. @classyhacker on twitter 2
  2. GO is the 2016 Programming language of the YEAR TIOBE

    Language Index http://www.tiobe.com/tiobe-index/ The TIOBE programming language of the year award goes to the language with the biggest annual popularity 3
  3. Getting Started Download Go https://golang.org/ $which go Setup GOPATH $echo

    $GOPATH Write helloworld.go in your favorite editor, See example. Execute $go run hello world.go
  4. //Executable commands must always use package main package main //An

    import path is a string that uniquely identifies a package import "fmt" //The main function in the main package is an entry point into the program func main() { fmt.Println("hello world") } Anatomy of Go hello world Namespace Dependencies Program entry point
  5. Q. Why is my trivial program such a large binary?

    ➔ ls -l total 3144 -rwxr-xr-x 1 aarti staff 1603520 Feb 2 18:57 helloworld -rw-r--r--@ 1 aarti staff 72 Feb 2 18:57 helloworld.go
  6. From Go FAQ’s “The linker in the gc tool chain

    creates statically-linked binaries by default. All Go binaries therefore include the Go run- time, along with the run-time type information necessary to support dynamic type checks, reflection, and even panic-time stack traces.” Q. Why is my trivial program such a large binary?
  7. Testing is built-in •Unit tests •$go test •Benchmark tests for

    performance •$go test -bench •Concurrency test via the race detector •$go test -race •Many more options: Coverage, Memory profiling •$go test —help
  8. DEMO Leap year test ➔ go test -v === RUN

    TestLeapYears --- PASS: TestLeapYears (0.00s) PASS ok _/Users/aarti/dev/presentation/testing 0.005s ➔ go test -bench . Benchmark400-8 3000000 579 ns/op PASS ok _/Users/aarti/dev/presentation/testing 2.317s
  9. Performance Scalability Concurrency Comprehensive list of Go users Infrastructure: Docker,

    InfluxDb, Kubernetes, Hashicorp Fits in easily in a microservices architecture Server side and System engineering focus Networking companies are starting to adopt it What GO is good at and who is using it?
  10. Built-in Data Structures Array: Fixed length and Type safe a

    :=[3]int {1,2,3} b :=[2]int {1,2} a == b is False. Mismatched types [2]int and [3]int Map: No Generics support so get’s awkward at times a := map[string]int{“a”:1, “b”:2} Slices: Used everywhere for flexibility, SUPER IMPORTANT. Must Read Blog Post on Go Slices and Internal d := []byte{'h', 'e', 'l', ‘l'} d = append(d,'o') fmt.Printf(“%s",d) => hello
  11. Q. What HTTP server should I use in Go? A.

    Use net/http directly from the standard library. It is one of the most important packages and allows you to build HTTP servers in Go.
  12. The Go standard library is designed with scaling in mind.

    So use the packages in the standard library first. Using frameworks to do even trivial tasks is common in other languages, not so much in Go.
  13. Instead of explicitly using locks to mediate access to shared

    data, Go encourages the use of channels to pass references to data between goroutines. - Share Memory By Communicating Blog Post Concurrency
  14. DEMO Concurrency Design a Rate Printer 1. The printer reads

    from a file 2. The printer writes to a file 3. Print the bytes/second at which the printer is printing every second 4. Source Code
  15. WHAT PEOPLE MISS Classes: Go has no classes, There are

    structs and interfaces. Generics: No Generics support. The built-in package has some helpers. Exceptions: Go does not have Exceptions so the error handling can be verbose. Dependency management: Does not provide a specific way to include a precise version of a library.
  16. Learning Resources Official Go tour.golang.org Go specification Effective Go Ultimate

    Go: Comprehensive online course resource exercism.io: Practice programming and get feedback Gopher Academy Blog Dave Cheney Blog gobyexample.com Ben Johnson Blog
  17. Active Supportive Community Gophercon Gobridge initiatives: Coding workshops for women

    WomenWhoGo Slack channel go nuts mailing list Golang Weekly newsletter
  18. Ecosystem Awesome Go: https://github.com/avelino/awesome-go Trending Github Repos: https://github.com/trending/go https://golanglibs.com I

    personally use the following libs regularly Errors: https://github.com/pkg/errors Logs: https://github.com/sirupsen/logrus RESTful API’s: https://github.com/gorilla/mux