at compile time, dynamic when asked for— are, for me, the most exciting part of Go from a language design point of view. If I could export one feature of Go into other languages, it would be interfaces. Page Title Page Subtitle https://research.swtch.com/interfaces
ʜΈ͍ͨͳ ‣ CVJMUJOؔͷߟ͑ํ ʮTMJDFͷDBQΛ૿͢ʯʹɺഒͷDBQΛ࣋ͭ TMJDFΛ࡞Γ͍͍ͤΑͶDPQZ ʮTMJDFͷՃʯʹɺదʹDBQ૿ͭͭ͠ ඌʹDPQZ͢Ε͍͍ΑͶBQQFOE ༷ɾػೳղઆ s = s[2:4] s = s[:cap(s)] Go Slices: usage and internals
͋ΔHPSPVUJOFͰॻ͖ࠐΈ͕͋ͬͨมΛ ผͷHPSPVUJOFͰಡΈऔΔ͜ͱ͕Ͱ͖Δ͜ͱʹ͍ͭͯ ༷ɾػೳղઆ The Go Memory Model *GZPVNVTUSFBEUIFSFTUPGUIJTEPDVNFOUUPVOEFSTUBOE UIFCFIBWJPSPGZPVSQSPHSBN ZPVBSFCFJOHUPPDMFWFS %POUCFDMFWFS
ԿΛอূ͢Δ͜ͱͰσʔλڞ༗Λ࣮ݱ͍ͯ͠Δ͔Λղઆ͢Δ ‣ ӈͷྫʢDIBOOFMʣͰ͋Ε 5IFXSJUFUPBIBQQFOTCFGPSFUIFTFOEPOD 5IFTFOEPODIBQQFOTCFGPSFUIFSFDFJWFPOD 5IFSFDFJWFPODIBQQFOTCFGPSFUIFQSJOU ༷ɾػೳղઆ Go Slices: usage and internals var c = make(chan int, 10) var a string func f() { a = "hello, world" c <- 0 } func main() { go f() <-c print(a) }
ԿΛอূ͢Δ͜ͱͰσʔλڞ༗Λ࣮ݱ͍ͯ͠Δ͔Λղઆ͢Δ ‣ ӈͷྫʢDIBOOFMʣͰ͋Ε 5IFXSJUFUPBIBQQFOTCFGPSFUIFTFOEPOD 5IFTFOEPODIBQQFOTCFGPSFUIFSFDFJWFPOD 5IFSFDFJWFPODIBQQFOTCFGPSFUIFQSJOU ༷ɾػೳղઆ Go Slices: usage and internals var c = make(chan int, 10) var a string func f() { a = "hello, world" c <- 0 } func main() { go f() <-c print(a) }
ԿΛอূ͢Δ͜ͱͰσʔλڞ༗Λ࣮ݱ͍ͯ͠Δ͔Λղઆ͢Δ ‣ ӈͷྫʢDIBOOFMʣͰ͋Ε 5IFXSJUFUPBIBQQFOTCFGPSFUIFTFOEPOD 5IFTFOEPODIBQQFOTCFGPSFUIFSFDFJWFPOD 5IFSFDFJWFPODIBQQFOTCFGPSFUIFQSJOU ༷ɾػೳղઆ Go Slices: usage and internals var c = make(chan int, 10) var a string func f() { a = "hello, world" c <- 0 } func main() { go f() <-c print(a) }
ԿΛอূ͢Δ͜ͱͰσʔλڞ༗Λ࣮ݱ͍ͯ͠Δ͔Λղઆ͢Δ ‣ ӈͷྫʢDIBOOFMʣͰ͋Ε 5IFXSJUFUPBIBQQFOTCFGPSFUIFTFOEPOD 5IFTFOEPODIBQQFOTCFGPSFUIFSFDFJWFPOD 5IFSFDFJWFPODIBQQFOTCFGPSFUIFQSJOU ༷ɾػೳղઆ Go Slices: usage and internals var c = make(chan int, 10) var a string func f() { a = "hello, world" c <- 0 } func main() { go f() <-c print(a) }
-PDL0ODF͕ʮͳʹΛอূͯ͘͠ΕΔ͔ʯͷ ղઆ͕͋Δ ‣ ϖʔδΛCFGPSFHVBSBOUFFͰHSFQ͢ΔͱಡΈ͍͢ ༷ɾػೳղઆ Go Slices: usage and internals var l sync.Mutex var a string func f() { a = "hello, world" l.Unlock() } func main() { l.Lock() go f() l.Lock() print(a) } var a string var once sync.Once func setup() { a = "hello, world" } func doprint() { once.Do(setup) print(a) } func twoprint() { go doprint() go doprint() } Lock Once
औΕΔσʔλʢGSPNIUUQTHPMBOHPSHQLHSVOUJNFQQSPG1SPpMFʣ - goroutine - stack traces of all current goroutines - heap - a sampling of memory allocations of live objects - allocs - a sampling of all past memory allocations - threadcreate - stack traces that led to the creation of new OS threads - block - stack traces that led to blocking on synchronization primitives - mutex - stack traces of holders of contended mutexes ‣ 1SPEVDUJPOTBGF͚ͩͲɺଟগσάϨ͢ΔΑɻNVMUJSFQMJDBͷ͏ͪͷQSPDFTT͚ͩʹ͠Α͏Ͷɻ ʜΈ͍ͨͳ͍ํͷίπΈ͍ͨͳͷॻ͍ͯ͋Δ ༷ɾػೳղઆ Diagnostics
FH ⭕ͯ͘Θ͔Γ͍͢UJNF MJTU IUUQ ❌ޠҎ্Θͳ͍DPNQVUF4FSWJDF$MJFOU [email protected] ⭕ʢઅ͋ΔʣུޠTUSDPOW TZTDBMM GNU Naming What's in a name? Image from https://talks.golang.org/2012/waza.slide