~/codex/golang
go notes
// syntax, patterns, things that clicked
basics
arithmetic operators
mostly the same as js but go is strict about types. integer division truncates, no implicit coercion, and ++ is a statement not an expression.
console output
go's fmt package. more explicit than console.log but more powerful. three families — print, sprintf, fprintf — each for a different job.
data types & variables
go is statically typed. types are checked at compile time, not runtime. no undefined, no null surprises, no implicit coercion.
short variable declaration
the := operator. you'll use this 90% of the time inside functions. faster to write, type is inferred, but has rules that'll trip you up.
concurrency
control flow
conditions & conditionals
if/else works like js but no parentheses, braces are mandatory, and there's an init statement that doesn't exist in js at all.
looping
go has one loop keyword — for. no while, no do-while. but for is flexible enough to do everything. range is your best friend for collections.
switch
go's switch is cleaner than js. no break needed, multiple values per case, and the expressionless form is a better if/else chain replacement.
core
functions
functions are first-class in go. multiple returns, variadic args, functions as values, factory pattern. this is the foundation of every middleware pattern you'll write.
interfaces
interfaces define behavior, not data. implicit implementation — if your struct has the methods, it satisfies the interface automatically. no implements keyword.
structs
go's way of modeling data. no classes, no inheritance. just fields, methods, and embedding. think typescript types but compiled and strict.
data structures
arrays
fixed size, value type, rarely used directly in real go code. understand them because slices are built on top of them.
maps
go's key-value store. like js objects but typed, stricter, and with a comma ok pattern you'll use constantly to avoid silent bugs.
slices
go's dynamic arrays. reference type, built on top of arrays, three things under the hood. this is what you'll actually use day to day.