Don t Go, Java!
Don t Go Java!
Don t Go Java! Edition 2019
Disclaimer
Disclaimer I actually like Go!
Guess The Movie
Guess The Movie
Guess The Movie
Guess The Movie
Who s That Dude? Chris Engelbert Senior Developer Advocate @ Instana Java-Passionate (10+ years) Go (2 years) Performance Garbage Collection Benchmark Fairytales
Who s That Dude? @instanahq
Who s That Dude? Adores TypeScript Prefers Kotlin Codes Java @instanahq
Who s That Dude? Kinda likes Go Adores TypeScript Prefers Kotlin Codes Java @instanahq
Who s That Dude? Kinda likes Go Adores TypeScript Forced to use JS Prefers Kotlin Totally hates Python Codes Java @instanahq
Who s That Dude? Kinda likes Go Adores TypeScript Forced to use JS Prefers Kotlin Totally hates Python Codes Java LOVES BEER! (Dah, German) @instanahq
What is?
What Is Go? s t r a P d o o G e h T : Go d e t a nion i p o s t I. 1 https://www.pexels.com/photo/blank-paper-with-pen-and-coffee-cup-on-wood-table-6357/
What Is Go? General Purpose Language Inception: 2009 Version 1.0: 2012 Current Release: 1.12.1
What Is Go?
What Is Go? Type Inference package main func main() { value := "my string"
What Is Go? Type Inference Package Declaration package main func main() { value := "my string"
What Is Go? Type Inference Package Declaration package main Main (Entry) Function func main() { value := "my string"
What Is Go? Type Inference Package Declaration package main Main (Entry) Function Variable Declaration func main() { value := "my string"
What Is Go? Type Inference Package Declaration package main Main (Entry) Function Variable Declaration func main() { value := "my string" Variable
What Is Go? Type Inference Package Declaration package main Main (Entry) Function Variable Declaration func main() { value := "my string" Variable Create and Infer Type
What Is Go? Type Inference Package Declaration package main Main (Entry) Function Variable Declaration func main() { value := "my string" Variable Some String Create and Infer Type
What Is Go? Type Inference package main func main() { value := "my string"
What Is Go? Type Inference package main func main() { value := "my string" Compile Error
What Is Go? Type Inference package main func main() { value := "my string Compile Error
What Is Go? Extensive Stdlib package main import "io/ioutil" func main() {
What Is Go? Extensive Stdlib package main Import Declaration import "io/ioutil" func main() {
What Is Go? Extensive Stdlib Archive (tar, zip, ) Sorting Byte Manipulation Math HTML Templates (Buffered) IO Time Debugging Reflection OS (Exec, File, ) Database (SQL) Encoding (base64, hex, csv, json, xml, ) Compression (bzip2, flate, gzip, ) Crypto (aes, dsa, rsa, sha, tls, ) Logging Net (TCP, UDP, Unix Socket, )
What Is Go? Extensive Stdlib package main import "io/ioutil" func main() {
What Is Go? Extensive Stdlib package main import "io/ioutil" func main() { Compile Error
What Is Go? Extensive Stdlib package main import "io/ioutil" func main() { Compile Error
What Is Go? Multi-Value Return func main() { x, y := findcoordinates("conference") func findcoordinates(place string) (x, y int) { return 0, 0
What Is Go? Multi-Value Return func main() { x, y := findcoordinates("conference") func findcoordinates(place string) (x, y int) { return 0, 0 Defines Two Return Values (both type int)
What Is Go? Automatic Resource Management package main import "os" func main() { file, _ := os.open("/tmp/foo") defer file.close()
What Is Go? Automatic Resource Management package main import "os" func main() { ignore return value file, _ := os.open("/tmp/foo") defer file.close()
What Is Go? Automatic Resource Management package main import "os" func main() { ignore return value file, _ := os.open("/tmp/foo") defer file.close() file.close() should be called on Method return
What else is? Unfortunately!
What Is Go too? - Unfortunately Error Handling func main() { file, err := os.open("/tmp/foo") if err!= nil { log.fatal(err) defer file.close()
What Is Go too? - Unfortunately Error Handling func foo() error { file, err := os.open("/tmp/foo") if err!= nil { return err defer file.close() return nil
What Is Go too? - Unfortunately Public Vs. (Package) Private func Foo() { func foo() {
What Is Go too? - Unfortunately Public Vs. (Package) Private public func Foo() { func foo() { private
What Is Go too? - Unfortunately Public Vs. (Package) Private? func 日本語 () {
What Is Go too? - Unfortunately Public Vs. (Package) Private private func 日本語 () {
What Is Go too? - Unfortunately Syntax func (f *foo) method(p1 *string) (foo, error) { if p1 == nil { return "", errors.new("nil pointer") return "foo", nil
What Is Go too? - Unfortunately Syntax Bind Method to Type Pointer-To-Foo func (f *foo) method(p1 *string) (foo, error) { if p1 == nil { return "", errors.new("nil pointer") return "foo", nil
What Is Go too? - Unfortunately Syntax func (f *foo) method(p1 *string) (foo, error) { if p1 == nil { return "", errors.new("nil pointer") return "foo", nil
What Is Go too? - Unfortunately Syntax func (f *foo(*string)) method(p1 *string) (foo, error) { if p1 == nil { return "", errors.new("nil pointer") return "foo", nil
What Is Go too? - Unfortunately
5 Things You Can Hate About Go But You Don t Have To
You re Crazy, But Don t You Worry!
You re Crazy, But Don t You Worry! func foo(var1 string) { { var1 := "bar" fmt.println(var1) break func main() { foo("foo")
You re Crazy, But Don t You Worry! func foo(var1 string) { { fmt := "bar" fmt.println(var1) break func main() { foo("foo")
You re Crazy, But Don t You Worry! type task struct { func main() { task := &task{
You re Crazy, But Don t You Worry! type task struct { func main() { instantiation task := &task{
You re Crazy, But Don t You Worry! type task struct { func main() { task := &task{ task = &task{
Clone Or Not Clone, That Is The Question!
Clone Or Not Clone, That Is The Question! type handle int func types(val interface{) { switch v := val.(type) { case int: fmt.println(fmt.sprintf("i am an int: %d", v)) switch v := val.(type) { case handle: fmt.println(fmt.sprintf("i am an handle: %d", v))
Clone Or Not Clone, That Is The Question! type handle int func types(val interface{) { switch v := val.(type) { reflective type case int: fmt.println(fmt.sprintf("i am an int: %d", v)) switch v := val.(type) { case handle: fmt.println(fmt.sprintf("i am an handle: %d", v))
Clone Or Not Clone, That Is The Question! func main() { var var1 int = 1 var var2 handle = 2 type handle int types(var1) types(var2) func types(val interface{) { switch v := val.(type) { case int: fmt.println(fmt.sprintf("i am an int: %d", v)) switch v := val.(type) { case handle: fmt.println(fmt.sprintf("i am an handle: %d", v))
Clone Or Not Clone, That Is The Question! func main() { var var1 int = 1 var var2 handle = 2 type handle = int types(var1) types(var2) func types(val interface{) { switch v := val.(type) { case int: fmt.println(fmt.sprintf("i am an int: %d", v)) switch v := val.(type) { case handle: fmt.println(fmt.sprintf("i am an handle: %d", v))
Clone Or Not Clone, That Is The Question! func main() { var var1 int = 1 var var2 handle = 2 type handle int types(var1) types(var2) func types(val interface{) { switch v := val.(type) { case int: fmt.println(fmt.sprintf("i am an int: %d", v)) switch v := val.(type) { case handle: fmt.println(fmt.sprintf("i am an handle: %d", v))
Clone Or Not Clone, That Is The Question! func main() { var var1 int = 1 var var2 handle = 2 type handle = int types(var1) types(var2) func types(val interface{) { switch v := val.(type) { case int: fmt.println(fmt.sprintf("i am an int: %d", v)) switch v := val.(type) { case handle: fmt.println(fmt.sprintf("i am an handle: %d", v))
Clone Or Not Clone, That Is The Question! type Callable func() func test(callable Callable) { callable() func main() { mycallable := func() { fmt.println("callable") test(mycallable)
Clone Or Not Clone, That Is The Question! type Callable func() func main() { callable1 := func() { fmt.println("callable1") func test(val interface{) { switch v := val.(type) { case func(): var callable2 Callable callable2 = func() { fmt.println("callable2") v() default: fmt.println("wrong type") test(callable1) test(callable2)
He Looks Lazy, Isn t He?
He Looks Lazy, Isn t He? func main() { functions := make([]func(), 3) for i := 0; i < 3; i++ { functions[i] = func() { fmt.println(fmt.sprintf("iterator value: %d", i)) functions[0]() functions[1]() functions[2]()
He Looks Lazy, Isn t He? func main() { functions := make([]func(), 3) map instantiation for i := 0; i < 3; i++ { functions[i] = func() { fmt.println(fmt.sprintf("iterator value: %d", i)) functions[0]() functions[1]() functions[2]()
He Looks Lazy, Isn t He? func main() { functions := make([]func(), 3) for i := 0; i < 3; i++ { map instantiation loop functions[i] = func() { fmt.println(fmt.sprintf("iterator value: %d", i)) functions[0]() functions[1]() functions[2]()
He Looks Lazy, Isn t He? func main() { functions := make([]func(), 3) for i := 0; i < 3; i++ { functions[i] = func() { map instantiation loop closure fmt.println(fmt.sprintf("iterator value: %d", i)) functions[0]() functions[1]() functions[2]()
He Looks Lazy, Isn t He? func main() { functions := make([]func(), 3) for i := 0; i < 3; i++ { functions[i] = func() { fmt.println(fmt.sprintf("iterator value: %d", i)) functions[0]() functions[1]() functions[2]()
He Looks Lazy, Isn t He? func main() { functions := make([]func(), 3) for i := 0; i < 3; i++ { functions[i] = func(i int) func() { return func() { fmt.println(fmt.sprintf("iterator value: %d", i)) (i) functions[0]() functions[1]() functions[2]()
He Looks Lazy, Isn t He? func main() { functions := make([]func(), 3) for i := 0; i < 3; i++ { i := i functions[i] = func() { fmt.println(fmt.sprintf("iterator value: %d", i)) functions[0]() functions[1]() functions[2]()
Aren t We All A Little Bit Gopher?
Aren t We All A Little Bit Gopher? type Sortable interface { Sort(other Sortable)
Aren t We All A Little Bit Gopher? type Sortable interface { Sort(other Sortable) type MyStruct struct{ func (m MyStruct) Sort(other Sortable) {
Aren t We All A Little Bit Gopher? type Sortable interface { Sort(other Sortable) type MyStruct struct{ func (m MyStruct) Sort(other Sortable) { func main() { var foo Sortable = &MyStruct{ foo.sort(&mystruct{)
Aren t We All A Little Bit Gopher? type Sortable interface { Sort(other Sortable) type MyStruct struct{ func (m MyStruct) Sort(other Sortable) {
Aren t We All A Little Bit Gopher? type Sortable interface { Sort(other Sortable) type MyStruct struct{ func (m MyStruct) Sort(other Sortable) { var _ Sortable = MyStruct{ var _ Sortable = (*MyStruct)(nil)
It s Nil Or Nothing!
It s Nil Or Nothing! type MyError string func (m MyError) Error() string { return string(m)
It s Nil Or Nothing! type MyError string func (m MyError) Error() string { return string(m) type error interface { Error() string
It s Nil Or Nothing! type MyError string func (m MyError) Error() string { return string(m)
It s Nil Or Nothing! type MyError string func (m MyError) Error() string { return string(m) func test(v bool) error { var e *MyError = nil if v { return nil return e func main() { fmt.println(nil == test(true)) fmt.println(nil == test(false))
Seriously? I Don t Give A FAQ!
Seriously? I Don t Give A FAQ! https://golang.org/doc/faq
Remember Not Here To Scare You!
Remember Not Here To Scare You! But There Will Be Dragons
? Questions???
? Thank You??