Open metaist opened 3 months ago
go install
makes a binary and puts it in $HOME/go/bin
(hello world is 1.9 MB!)go fmt
uses tabs! (meh, it's the language standard and I can edit my .editorconfig
)go mod tidy
when you add new dependenciesgo test
runs the lightweight test framework (How do I get coverage?)https://go.dev/doc/effective_go
.X()
for the getter of .x
and .SetX()
to be its setter.-er
(Reader, Writer, etc.)MixedCaps
or mixedCaps
switch
as idiomatic long if-if else-else
; can have comma-separated lists for casesbreak
to a label (like in js)char
in Ciota
?
const
and is incremented for every non-blank, non-comment line by oneconst
type Sequence []int
can be "cast" to []int(s)
because we're just pretending it's a different type)https://gobyexample.com/worker-pools
I was surprised this syntax didn't work:
for r := range out {
fmt.Println("Got result:", r)
}
Meaning, it ran until the out
channel was out of things to do and then crashed.
Are there optional arguments? Nope and no overloading either. https://go.dev/doc/faq#overloading
Is there an equivalent of Python's range
(formerly xrange
)?
Not really. Just use for
.
Is there an equivalent of yield
?
No. Just use channels.
https://go.dev/talks/2013/go4python.slide#20
Even cleaner: https://go.dev/talks/2013/go4python.slide#21
Completed https://go.dev/tour/
if
andswitch
similar tofor
; variables exist only within scopedefer
is nice for all kinds of cleanup (close file, mutex unlock); can modify named return values