GO
157 bites tagged GO — interview questions with model answers, and 60-second explainers.
Go's sync.Map: A Specialized Concurrent Map
Go's `sync.Map` is a concurrent map optimized for keys written once and read many times. It's ideal for long-lived caches, but it's not a generic replacement for a map with a mutex. The footgun is using it for frequent writes, which can be slower.
Go Maps: Your Built-in Hash Table
Go maps are the language's built-in hash tables for fast key-value lookups. Use `make(map[K]V)` to initialize one before writing. The biggest footgun is writing to a `nil` map, which causes a runtime panic. Always initialize your maps first.
Go Pointers: Memory Addresses, Not Math
Go pointers are street addresses for data. Instead of copying a large struct, you pass its memory address. This lets functions modify the original value and is critical for performance.
Go's `defer`: Guaranteed Cleanup
Go's `defer` statement guarantees cleanup by running a function call just before the parent function returns. It's perfect for closing files or unlocking mutexes right where you acquire them. The footgun: multiple defers run in last-in, first-out order.
Go Slices: A Window into an Array
Think of a Go slice not as a list, but as a lightweight window into an underlying array. It's used everywhere for managing sequences of data. The footgun: since slices can share memory, modifying one can unexpectedly alter another.
Go vs. Rust: Variable Mutability by Default
Rust variables are immutable by default; Go's are mutable. Rust forces you to opt-in to changeability with `mut` for compile-time safety. Go prioritizes convenience, trusting the developer.
Go's Garbage Collector: The Concurrent Cleaner
Go's garbage collector is a concurrent cleaning crew, freeing memory while your program runs. It automatically reclaims unused memory, preventing leaks without manual `free()` calls. The footgun is assuming it's free; excessive allocations create GC pressure.
Go Interfaces: Describe Behavior, Not Data
Go interfaces define behavior, not data. A type satisfies an interface implicitly by implementing its methods, without an `implements` keyword. This enables writing flexible functions, like `io.Writer` handling files or HTTP responses.
Goroutines
A goroutine is a lightweight function managed by Go's own runtime scheduler rather than the operating system, letting a single program run hundreds of thousands of concurrent tasks cheaply instead of the handful an OS thread model allows.
Go's Design Philosophy: Engineering Over Novelty
Go's design philosophy is engineering over novelty, built to solve Google's problems with slow builds and complexity in massive codebases. It excels at large, networked systems where maintainability and fast compilation are critical.
Kubebuilder: Build Kubernetes APIs the Canonical Way
Kubebuilder is a framework for scaffolding custom Kubernetes APIs, letting you define your own resources like `MyWebApp`. Use it to extend Kubernetes with declarative APIs, making your app a first-class citizen.
controller-runtime: The Engine for Kubernetes Operators
Think of controller-runtime as the standard library for writing Kubernetes controllers. It handles the boilerplate of watching resources and reconciling state, forming the foundation for tools like Kubebuilder and Operator SDK.
Operator SDK: Build Kubernetes Operators Faster
The Operator SDK is a developer toolkit that scaffolds the boilerplate for building, testing, and packaging Kubernetes Operators. Use it to automate complex application lifecycle management, like deploying a database cluster that can self-heal and perform…
Get GO bites daily.
Five a day, five minutes, offline. With quizzes so it sticks.
Open testing — you’ll join as an early tester.