GO
157 bites tagged GO — interview questions with model answers, and 60-second explainers.
Go Escape Analysis Chooses Stack Over Heap
Go escape analysis is the compiler pass that decides whether a variable lives on the stack or heap. It avoids heap allocations when data stays local, but any pointer that outlives its function escapes. The footgun is assuming small values never allocate.
Structs: Go's Plain Memory vs Rust's Ownership
Structs bundle named fields into a custom type. Use them when tuples or maps collapse under many values. The footgun is assuming the same syntax means the same rules: Go zero-values fields silently, while Rust demands explicit initialization unless you derive…
Primitive Scalars: Go vs Rust
Go's int grows with the architecture; Rust fixes sizes like i32 at compile time. Use Go's int for loops and Rust's i32 for counters, but both require explicit casts to mix. Assuming Go's int is 64-bit breaks 32-bit builds, and Rust's as truncates silently.
TCP Listeners: Go vs Rust
Go spins up TCP listeners and handles connections with lightweight goroutines—1 million costs ~500MB—but GC pauses introduce 2-5ms latency. Rust trades boilerplate for zero-cost safety and consistent sub-100µs response times without garbage collection.
go vet: Catch Bugs Compilers Allow
go vet catches suspicious constructs the compiler ignores, like Printf argument mismatches. Run it in CI to spot concurrency and formatting bugs early. It relies on heuristics, so a clean report does not guarantee correctness and false positives can occur.
CSP: Model Concurrency with Message Passing
CSP treats concurrency as isolated processes talking through channels, not threads fighting over shared memory. It shaped Go, Erlang, and occam. Engineers often retrofit shared-state patterns into channel-based code and reintroduce race conditions.
go.mod: Root of Go Module Identity
A go.mod file anchors a Go module, declaring its canonical path and dependencies to turn a directory into a versioned unit. Every project needs one at its root, and the path dictates how others import your packages.
Explain concurrency vs parallelism: junior paragraph, UI tooltip, justify
This tests audience-adaptive technical writing and conceptual precision. A strong answer gives the junior a structural analogy, the UI a one-sentence action metric, and justifies why detail and brevity swap by context.
Design a golden path CI/CD pipeline for a Go API
Propose build, test, SAST, containerize, deploy stages with hooks or config overlays for flexibility. Balancing standardization with team autonomy. A rigid pipeline with no escape hatches or weak security gates.
Daemonizing Go/Rust Apps: Let the OS Do It
Daemonizing an app means running it as a background service, detached from your terminal. This is essential for web servers or job processors. The common footgun is writing custom daemon logic instead of using a system service manager like systemd.
Terminal User Interfaces (TUIs): GUIs for the Console
A TUI is a graphical interface built from text, offering rich interactivity without leaving the console. Use them for system monitoring (btop), file management, or database clients. The footgun: don't confuse them with CLIs; TUIs are stateful apps.
Go's Functional Options Pattern for Flexible APIs
The functional options pattern uses functions to set optional struct fields, making APIs flexible and readable. It's common for complex constructors like servers or DB clients.
Go's Worker Pool Pattern: Capping Concurrency
A worker pool caps concurrency by using a fixed number of goroutines to process jobs from a queue. Use it for rate-limiting API calls or processing files without spawning unlimited goroutines.
Go Cobra: Build Complex CLIs Like `kubectl`
Cobra gives your Go CLI a command tree, like `git remote add`. It's for apps with nested commands and persistent flags, not just simple tools. The footgun is using it for a single command when Go's `flag` package would suffice.
Go Assembly: A Semi-Abstract Instruction Set
Go's assembler isn't a direct mapping to machine code; it's a semi-abstract instruction set. A `MOV` might become a `clear` or `load`. This is what you see with `go tool compile -S`. The footgun is assuming your assembly maps 1:1 to the final machine code.
Cgo: The Bridge Between Go and C Code
Cgo is Go's bridge to the C world, letting you call C functions and use C types from your Go code. It's for leveraging existing C libraries or low-level OS APIs. The footgun: cgo calls have high overhead and break Go's simple cross-compilation.
Go's `unsafe` Package: Breaking the Rules for Performance
Go's `unsafe` package lets you bypass type safety, treating memory like C with raw pointers for performance gains. It's used for low-level optimizations and C interoperability. The footgun: its behavior isn't guaranteed across Go versions, making code fragile.
Go Reflection: Inspecting Types at Runtime
Go's `reflect` package lets your program inspect and manipulate variables of unknown types at runtime. This is the engine behind JSON marshaling and generic frameworks. Misuse leads to slow code and runtime panics; always prefer interfaces when possible.
Go Linker Flags: Injecting Data at Build Time
Go's `-ldflags` lets you inject data into your program at build time. This is perfect for embedding version numbers or git commit hashes into variables without hardcoding them. The main footgun is that the target variable must be a top-level string.
Go Execution Tracer: Pinpointing Concurrency Bottlenecks
Go's Execution Tracer creates a visual timeline of your program, capturing goroutine state changes, syscalls, and GC events. It's essential for diagnosing subtle concurrency issues like lock contention. The main footgun is misusing annotations for work.
Go Fuzz Testing: Automated Bug Discovery
Go's fuzz testing automatically generates strange inputs to crash your code, finding bugs you'd never think to test. It's ideal for stress-testing parsers or security-sensitive functions.
Go Memory Profiling with pprof
pprof takes a snapshot of your Go app's memory usage, showing which functions allocate the most. Use it to diagnose high memory consumption or find leaks. A common footgun is profiling total allocations (`allocs`) instead of current memory use (`heap`).
Go's pprof: Finding Your Code's Hotspots
pprof is a heat map for your code, revealing which functions consume the most CPU. It samples your program's call stacks to find performance hotspots. Use it to diagnose slow API endpoints or high-CPU background jobs. The footgun: profiling under no load.
Mocking in Go: Swap Real Code for Test Doubles
Mocking in Go uses interfaces to swap slow dependencies like `time.Sleep` with fast fakes in tests, keeping your test suite quick. Use it for network calls or database access. The footgun is testing implementation details instead of observable behavior.
Get GO bites daily.
Five a day, five minutes, offline. With quizzes so it sticks.
Open testing — you’ll join as an early tester.