Skip to content

Instantly share code, notes, and snippets.

@mweitzel
Created March 23, 2022 14:30
Show Gist options
  • Save mweitzel/52560567a92ea18079a2b52d999707d9 to your computer and use it in GitHub Desktop.
Save mweitzel/52560567a92ea18079a2b52d999707d9 to your computer and use it in GitHub Desktop.
golang thing thang
package main
import (
"fmt"
)
type thing struct {
str string
}
func (thinger thing) BadSet(str string) {
thinger.str = str
}
func (thinger *thing) GoodSet(str string) {
thinger.str = str
}
func main() {
thinger := thing{}
thinger.BadSet("one")
fmt.Println(thinger)
thinger.GoodSet("two")
fmt.Println(thinger)
thinger2 := thinger
thinger.GoodSet("three")
fmt.Println(thinger2)
fmt.Println("--------------")
thanger := &thing{}
thanger.BadSet("one")
fmt.Println(thanger)
thanger.GoodSet("two")
fmt.Println(thanger)
thanger2 := thanger
thanger.GoodSet("three")
fmt.Println(thanger2)
}
@mweitzel
Copy link
Author

A snippet I shared with a handful of folks who are learning go.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment