Skip to content
tezvyn:

GO

157 bites tagged GO — interview questions with model answers, and 60-second explainers.

Go & Rust1 min read

Diagnosing Go memory leaks with pprof heap profiles

Expose net/http/pprof, grab /debug/pprof/heap, analyze inuse_space for live retention versus alloc_space for cumulative allocation; rising inuse over time points to a leak. production profiling with pprof.

Go & Rust1 min read

Cancellation: Go context vs Rust sync stdlib

Go's context.Context threads a Done channel and deadline through call chains; Rust std has no built-in cancellation, so you wire an AtomicBool or channel and check it. cancellation propagation models.

Go & Rust1 min read

Network read/write timeouts in Go vs Rust stdlib

Go uses SetReadDeadline/SetWriteDeadline as absolute times; Rust uses set_read_timeout/set_write_timeout as durations on TcpStream. stdlib IO timeout APIs and design philosophy.

Go & Rust1 min read

Concurrent TCP server: Go goroutines vs Rust std::thread

Both accept in a loop; Go spawns a goroutine per connection (go handle(conn)); Rust spawns an OS thread (thread::spawn moving the stream). stdlib networking and concurrency.

Go & Rust1 min read

Rust async/await vs Go goroutines

Go schedules goroutines on a built-in runtime transparently; Rust futures are inert until polled by an external runtime like Tokio, and async colors functions. async execution models.

Go & Rust1 min read

Sharing mutable state: Go mutex vs Rust Arc Mutex

Go uses sync.Mutex by convention; Rust wraps data in Arc<Mutex<T>> so locking is mandatory, enforced by Send/Sync and the borrow checker. shared-state concurrency and compile-time safety.

Go & Rust1 min read

Value versus pointer receivers and interface satisfaction

Value-receiver methods belong to both T and *T, but pointer-receiver methods belong only to *T, so a value of T may not satisfy an interface. method sets and interface satisfaction.

Go & Rust1 min read

When to panic in Go versus Rust

Both reserve panic for unrecoverable bugs and use values, Result or error, for expected failures; Rust's type system pushes more cases to Result. error philosophy and panic boundaries.

Go & Rust2 min read

Rust borrow rules versus Go race prevention

Rust's aliasing-XOR-mutability rule plus Send and Sync make races a compile error; Go prevents them at runtime via channels, mutexes and the race detector. how each language stops data races.

Go & Rust1 min read

Refactoring under Go simplicity versus Rust correctness

Rust's type system catches broken invariants at compile time so refactors are guided; Go's explicitness keeps code readable but shifts safety to tests and discipline. how language philosophy shapes refactors.

Go & Rust1 min read

I/O Stream Abstractions

I/O stream abstractions like Go's io.Reader and io.Writer model data as a flow of bytes behind a tiny interface, so files, sockets, buffers and encoders compose interchangeably without each one knowing the others' concrete type.

Go & Rust1 min read

Implicit Interface Satisfaction in Go

Go types satisfy an interface automatically by having the right methods, with no explicit implements declaration. This structural typing decouples implementations from interface definitions, so you can define interfaces around how you use a type without…

Go & Rust2 min read

Explain the performance overhead of a cgo call

Tests cgo transition penalties and scheduler semantics. A strong answer cites the ~100x overhead (~171ns vs ~1.8ns), notes C blocks an OS thread and starves the scheduler, and warns about memory copy taxes. Red flag: claiming cgo is free or ignoring blocking.

Go & Rust2 min read

Use a C malloc'd char* in Go and Rust, then free it

Tests FFI allocator discipline. In Go, copy with C.GoString then C.free the *C.char. In Rust, read via CStr::from_ptr, copy to String, then libc::free. Red flag: letting Go GC or Rust Drop manage C memory, or using CString::from_raw on C malloc'd pointers.

Go & Rust2 min read

Pass a string from Go and Rust to C safely

This tests FFI ownership and null-termination. In Go, use C.CString then C.free it. In Rust, create a std::ffi::CString, bind it to a let, then pass as_ptr while the binding lives. Red flag: claiming Rust is auto-safe without mentioning the temp-drop gotcha.

Go & Rust2 min read

Purpose of Go import C and Rust equivalent mechanism

This tests FFI entry points: Go's import "C" activates cgo to reference C symbols directly, while Rust uses an unsafe extern "C" block to declare external functions. A red flag is calling either a normal import or omitting unsafe in Rust.

Go & Rust2 min read

In Go's reflect package, what is settability and how is it obtained?

This tests whether you know reflection mutates only addressable storage. Settability means a Value points to actual memory; obtain it by calling reflect.ValueOf on a pointer then Elem, or on slice elements. Set panics when the Value is a copy, not an address.

Go & Rust2 min read

Using reflect, iterate a pointer-to-struct's fields

Tests fluency with Go reflection for indirection and field traversal. Outline: ValueOf/TypeOf, guard IsValid, check Kind==Ptr, Elem to struct, loop NumField with Type for names and Value for values. Red flag: Field() on the pointer before Elem panics.

Go & Rust2 min read

What does unsafe enable in Go and Rust? List two operations.

Go unsafe enables pointer arithmetic and type punning; Rust unsafe permits raw pointer dereferencing and FFI. Your grasp of where each language drops memory-safety guarantees.

Go & Rust2 min read

What is go generate and how does it differ from make?

This tests whether go generate is a pre-build code generator, not a build system. Strong answers cover //go:generate directives, no dependency analysis, and committing generated files. A red flag is calling it a make replacement or an automatic build step.

Go & Rust2 min read

Compare Go and Rust approaches to exposing profiling data

Contrast Go's pprof import with Rust crates or profilers, noting runtime versus OS-level sampling. Trade-offs between Go's pull model and Rust's push or attach models. Claiming Rust has a std-lib pull endpoint like Go.

Go & Rust2 min read

Explain fuzz testing and set up a basic fuzz test

This tests coverage-guided fuzzing and toolchain wiring. Strong answer: defines fuzzing as automated input mutation driven by code coverage, contrasts it with hand-written examples, and sketches Go's FuzzXxx or Rust's cargo-fuzz setup.

Go & Rust2 min read

Generate a Go CPU profile and visualize it as a flame graph

This tests Go profiling workflow and flame graph literacy. A good answer covers net/http/pprof setup, go tool pprof collection, flame graph generation, and reading width as cumulative CPU time and height as call depth. Red flag: width means call count.

Go & Rust2 min read

How do you use ResetTimer, StopTimer, and RunParallel in Go benchmarks?

Tests Go benchmark timer hygiene and parallel execution. A strong answer covers b.StopTimer before setup, b.ResetTimer before the loop, and b.RunParallel for CPU-bound scaling. A red flag is resetting without stopping or using parallel benchmarks for I/O.

Get GO bites daily.

Five a day, five minutes, offline. With quizzes so it sticks.

Open testing — you’ll join as an early tester.