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

mercari.go#10 - About Go Beginner's Training at...

mercari.go#10 - About Go Beginner's Training at GopherCon2019

Presentation about a workshop, "Go Beginner's Training" at the GopherCon 2019, San Diego, USA

Avatar for Jun "Mark" Hahn

Jun "Mark" Hahn

August 20, 2019

Other Decks in Technology

Transcript

  1. 1 Confidential - Do Not Share About “Go Beginners’ Training”

    Workshop at GopherCon2019 + @ Mercari, Inc. Software Engineer-Backend Mark GitHub & Twitter: @TangoEnSkai
  2. Languages to Learn: MAU in GitHub, 2011~2018 • Go’s MAU

    ◦ 0.5% - 2011 ◦ 1.0% - 2013 ◦ 2.0% - 2014
  3. Languages to Learn: MAU in GitHub, 2011~2018 • Go’s MAU

    ◦ 0.5% - 2011 ◦ 1.0% - 2013 ◦ 2.0% - 2014 ◦ 4.0% - 2017
  4. Languages to Learn: MAU in GitHub, 2011~2018 • Go’s MAU

    ◦ 0.5% - 2011 ◦ 1.0% - 2013 ◦ 2.0% - 2014 ◦ 4.0% - 2017 ◦ 10.0% - ???
  5. Languages to Learn: MAU in GitHub, 2011~2018 • Go’s MAU

    ◦ 0.5% - 2011 ◦ 1.0% - 2013 ◦ 2.0% - 2014 ◦ 4.0% - 2017 ◦ 10.0% - ???
  6. Backgrounds • Go is Getting Popular ◦ A Lot of

    Companies are using Go ▪ Gophers, gophers, and more gophers! ▪ More Go developer needed in the industry ▪ Beginner’s training is important! ▪ GopherCon2019 supported by:
  7. Backgrounds • Go is Getting Popular ◦ A Lot of

    Companies are using Go ▪ Gophers, gophers, and more gophers! ▪ More Go developer needed in the industry ▪ Beginner’s training is important! ▪ GopherCon2019 supported by:
  8. Today’s Topic: the Workshop • Go Beginner’s Training by: ◦

    Jay McGavren (Author of Head First Go) ▪ 4 years experience as a software development trainer ▪ Frequent conference speaker, an all-round mentor for dev. • Session ◦ Wed. 24th of July, 2019 - 9.00AM to 5.00PM (8 Hours)
  9. Today’s Topic: the Workshop • Go Beginner’s Training by: ◦

    Jay McGavren (Author of Head First Go) ▪ 4 years experience as a software development trainer ▪ Frequent conference speaker, an all-round mentor for dev. • Session ◦ Wed. 24th of July, 2019 - 9.00AM to 5.00PM (8 Hours) • 2 Software Engineers from Mercari Inc. Attended ◦ New Grad, Joined Mercari in April 2019 ▪ Mark Hahn ▪ Hunter Chen
  10. Our Objectives • Learn How to Use Go as a

    Beginner ◦ Exercise and Hands-On Examples ▪ Teaching style ▪ How people learn Go
  11. Our Objectives • Learn How to Use Go as a

    Beginner ◦ Exercise and Hands-On Examples ▪ Teaching style ▪ How people learn Go • Take This Learning Experience and Share ◦ Interns, New Grads, Mentors & Mentees ▪ 1 day workshop for fast grasp to start with Go ▪ Then, they can start learning more advanced topics
  12. Training Overview • From Very Basic Topics + @ ◦

    Basics: syntax, tools, functions, … ◦ Data Structures: slices, maps, structs, … ◦ Defining: Custom Types, Interfaces ◦ Creating & Using Packages ◦ Reading: Documentations ◦ Error Handling: defer, panic, ... ◦ Concurrency: goroutines, channels, … ◦ Ending: Next Topics + Other Resources • Prerequisites: Don’t Need to be Go Expert, Installing Go, Go Tour
  13. Why Go? • Go at a Glance ◦ C-like syntax

    ◦ Compiles to native code ◦ Type-safe ◦ Garbage collected ◦ Concurrency built into the language
  14. Why Go? • Go at a Glance ◦ C-like syntax

    ◦ Compiles to native code ◦ Type-safe ◦ Garbage collected ◦ Concurrency built into the language • “Famous” Examples ◦ Docker: “Why did we decide to write Docker in Go” ◦ K8s: Go isn’t overly complex; feels of C w/ adv. Features is a great combo; Garbage collection
  15. Before the Exercise/Hands-On Session • Tools Included in Go ◦

    `go fmt` - code style, goimports, ... ◦ `go run` - compile and run w/o saved executable files ◦ `go build`- compile `*.go` into an executable • Cross-Compilation ◦ For Windows from macOS $ env GOOS=windows ENV=amd64 go build main.go $ ls -la -rwxr-xr-x 1 hahn staff 7579648 Aug 18 13:01 main.exe -rw-r--r-- 1 hahn staff 2384 Aug 18 13:00 main.go
  16. Writing Go Program • Go File Layout + @ ◦

    Package clause, imports, code ◦ main package, calling functions • Exercises with Each Topic ◦ A Short Program ◦ … ◦ … ◦ … ◦ … ◦ goroutines, channels, ...
  17. Exercises for The Training • Using Go Playground ◦ A

    bit of theory ◦ Post a link with exercise ◦ Visit the link and follow the instruction ▪ Add codes, fill in blanks, etc. ◦ Cheat-sheet given as hints
  18. Exercises for The Training • Using Go Playground ◦ A

    bit of theory ◦ Post a link with exercise ◦ Visit the link and follow the instruction ▪ Add codes, fill in blanks, etc. ◦ Cheat-sheet given as hints • 2 Parts for Each Topic ◦ 1. Concepts in few sentences ▪ with Example codes ◦ 2. Exercise: Main Part of the Workshop !!!
  19. Exercises’ Topics A short program Variables `fmt.Printf` Type Conversion `if`

    and `for` Declaring Functions Passing Pointers `go get` Using Package Documentation Slices Maps Struct Types Defined Types Pointer Receivers Encapsulation Interfaces Handling Errors Goroutines and Channels
  20. Exercises’ Topics A short program Variables `fmt.Printf` Type Conversion `if`

    and `for` Declaring Functions Passing Pointers `go get` Using Package Documentation Slices Maps Struct Types Defined Types Pointer Receivers Encapsulation Interfaces Handling Errors Goroutines and Channels
  21. Type Conversion: Part 1 - Concepts w/ Code • Given

    Code: var length float64 = 1.2 var width int = 2 length = width // Can't assign an `int` value to a `float64` variable: • Compile Error cannot use width (type int) as type float64 in assignment
  22. Type Conversion: Part 1 - Concepts w/ Code • Given

    Code: var length float64 = 1.2 var width int = 2 // Can't do a math operation with a float64 and an int: fmt.Println("Area is", length*width) // Or a comparison: fmt.Println("length > width?", length > width)
  23. Type Conversion: Part 1 - Concepts w/ Code • Given

    Code: var length float64 = 1.2 var width int = 2 // But you can if you do type conversions! fmt.Println("Area is", length*float64(width)) fmt.Println("length > width?", length > float64(width)) • Output: Area is 2.4 length > width? false
  24. Type Conversion: Part 2 - Exercise • Cheat Sheet ◦

    can’t do math operations or comparisons ▪ between values of two different types. ◦ But, we can convert values ▪ From one type to another ▪ Using conversions ◦ A conversion takes the form: ▪ `targetType(valueToConvert)`
  25. Type Conversion: Part 2 - Exercise Solution package main import

    ( "Fmt" ) func main() { var price int = 100 fmt.Println("Price is", price, "dollars.") var taxRate float64 = 0.08 var tax float64 = float64(price) * taxRate fmt.Println("Tax is", tax, "dollars.") var total float64 = float64(price) + tax fmt.Println("Total cost is", total, "dollars.") var availableFunds int = 120 fmt.Println(availableFunds, "dollars available.") fmt.Println("Within budget?", total <= float64(availableFunds)) }
  26. Pointer Receiver : Part 1 - Concepts w/ Code •

    Given Code: ◦ Added an `Obfuscate()` method to `Coordinates` ◦ Not Working Correctly! func (c Coordinates) Obfuscate() { c.Latitude = math.Round(c.Latitude) c.Longitude = math.Round(c.Longitude) } func main() { c := Coordinates{Latitude: 37.42, Longitude: -122.08} c.Obfuscate() fmt.Println(c.Latitude, c.Longitude) // => 37.42 -122.08
  27. Pointer Receiver : Part 1 - Concepts w/ Code •

    Problem: ◦ Pass-by-value ◦ Receiver parameters get a copy of the original value ◦ Modify receiver parameter? You are only changing “the copy” • To Fix: ◦ Change the type of the receiver parameter to a pointer func (c *Coordinates) Obfuscate() { c.Latitude = math.Round(c.Latitude) c.Longitude = math.Round(c.Longitude) }
  28. Pointer Receiver: Part 2 - Exercise • Cheat Sheet type

    User struct { Name string } func (u *User) AlterName() { u.Name = strings.ToUpper(u.Name) }
  29. Pointer Receiver: Part 2 - Exercise Solution // All of

    a type's methods should use pointer receivers, // if any of them do. func (r *Rectangle) Area() float64 { return r.Length * r.Width } func (r *Rectangle) Perimeter() float64 { return (2 * r.Length) + (2 * r.Width) } // Make sure to use a pointer receiver, so you're modifying // the receiver itself and not a copy of it. func (r *Rectangle) Scale(factor float64) { // The receiver pointer is automatically dereferenced when accessing // the struct fields below. // Multiply Length by "factor" and assign the result back to the field. r.Length *= factor // Multiply Width by "factor" and assign the result back to the field. r.Width *= factor }
  30. And Others... • Entire Materials Available Here: ◦ `https://is.gd/gophercon_beginners` ▪

    Can finish all approx. 3hr to 8hr (for new gophers) • Where to Go Next? ◦ `go test` ◦ Web development: `net/http` package ◦ Other Resources: ▪ How to Write Go Code - golang.org/doc/code ▪ Effective Go, Standard Library Docs, ▪ Books - the Go Programming Language, Head First Go
  31. Conclusion • Go is Getting Popular (and Already Widely-Used)! ◦

    It’s growing in GitHub, companies, and schools • We Can Learn Go Basics in “ONE” Day ◦ Go is a simple language • We Could Also Encourage Your Friends to Try Go ◦ You can freely access the workshop’s material • Let’s Enjoy Go Programming :) ◦ Make things in Go !
  32. References • Ranking Programing Languages by Github Users by Ben

    Frederickson ◦ Article with Images • Presentation at GopherCon2019 by Jay McGavren ◦ GitHub Markdown Note • Credits for Gopher Images by Maria Letta ◦ GitHub Repo