More in Go & Rust — page 5
What Go tool detects data races and how do you invoke it?
This tests Go's built-in race detector. A strong answer names the -race flag, notes it instruments memory accesses to catch concurrent unsynchronized reads/writes, and shows go test -race. A red flag is confusing it with static analysis or external tools.
What is the difference between Cargo.toml and Cargo.lock?
WHAT IT TESTS: Understanding reproducible builds and Cargo's dependency model. ANSWER OUTLINE: Cargo.toml declares broad requirements; Cargo.lock pins exact resolved versions. RED FLAG: Saying lockfiles are optional for apps or that both files are hand edited.
How do you initialize and manage Go dependencies?
WHAT IT TESTS: Go Modules workflow knowledge. ANSWER OUTLINE: init with go mod init; use go get and go mod tidy; go.mod sets path and versions, go.sum stores checksums for verified builds. RED FLAG: saying go.sum is optional or that go.mod pins exact content.
When should Rust atomics replace a Mutex, and how do orderings work?
WHAT IT TESTS: Lock-free costs and hardware reordering. ANSWER OUTLINE: Atomics replace mutexes for counters; Relaxed is atomicity only, SeqCst adds global order, weaker ones skip fences on ARM. RED FLAG: Atomics as a blind faster Mutex.
Go select vs Rust select! fairness and determinism
This tests runtime fairness in concurrent primitives. Contrast Go's pseudo-random case selection with Tokio's randomized default and its opt-in biased; top-down mode. Red flag: claiming Go uses source order or that Rust randomization is unavoidable.
What is Go's context package and how do you use WithCancel?
This tests cancellation propagation. A good answer says Context carries deadlines, signals; derive a child with WithCancel, pass it to worker, then call cancel to unblock ctx.Done. Bad: storing context in structs, leaking cancel functions, or ignoring Done.
Buffered vs unbuffered Go channels and deadlock scenario
Tests channel synchronization semantics. Unbuffered channels block until sender and receiver rendezvous; buffered channels block only when full or empty. Deadlock: goroutine sends on unbuffered channel with no receiver.
How do Send and Sync prevent data races? Give a Send-but-not-Sync example.
WHAT IT TESTS: Rust's thread-safety model. ANSWER OUTLINE: explain Send moves values and Sync allows shared references across threads; give Cell as Send but not Sync because it has interior mutability. RED FLAG: conflating them or naming Rc, which lacks both.
What is the fundamental difference between a goroutine and an OS thread?
This tests your grasp of Go's M:N scheduler. A strong answer notes that goroutines are runtime-managed, multiplexed onto OS threads, and use far less memory per unit, enabling thousands of concurrent tasks.
Describe Rust's orphan rule and its ecosystem purpose
WHAT IT TESTS: Trait coherence across crates. ANSWER OUTLINE: State that either trait or type must be local; explain this stops conflicting foreign impls; note crates.io would see silent impl collisions breaking downstream builds.
Static dispatch with impl Trait versus dynamic dispatch with Box<dyn Trait>
Tests monomorphization versus vtables. Note: static dispatch monomorphizes for zero-cost abstraction but bloats code; dynamic dispatch uses vtables for smaller binaries but adds indirection.
Explain Go's empty interface, safe usage, and runtime risks
WHAT IT TESTS: Go's universal value box and type erasure. ANSWER OUTLINE: interface{} (alias any) holds values; unpack with type switches or ok assertions; risks are panics from bare assertions and nil interface vs nil concrete value confusion.
What is the difference between defining a Rust trait and implementing it?
WHAT IT TESTS: Knowledge of declaration versus implementation in Rust traits. ANSWER OUTLINE: Define with trait and signatures; implement with impl Trait for Type and concrete bodies. RED FLAG: Mixing up traits and structs or omitting for.
How does a Go type satisfy an interface? Provide an io.Reader example.
This tests implicit structural typing in Go. A type satisfies an interface by implementing every required method with exact signatures; no declaration links them. A red flag is claiming you need an implements keyword or explicit conformance.
Design a custom Go error type with context, Is, As, and Unwrap
This tests Go 1.13 error wrapping and Unwrap conventions. Answer: struct with Err and context fields; implement Error and Unwrap; note errors.Is and errors.As walk the chain. Red flag: stringifying the error via fmt.Errorf %v, which severs unwrapping.
How does the question mark operator use From to unify error types?
This tests Rust error conversion mechanics. You define a unified enum error and implement From for each source error so ? automatically converts via From::from. A red flag is suggesting manual match or map_err on every call instead of trait-based conversion.
What is the difference between unwrap and expect on Option and Result?
It tests your Rust error-handling discipline and justified panics. Both extract values or panic, but expect adds a custom message. Use them only for unrecoverable invariant violations, not routine errors. A red flag is using them as lazy error propagation.
Difference between errors.Is and errors.As in Go
This tests error-chain inspection in Go. errors.Is checks sentinel equality through wrapping, such as os.ErrNotExist. errors.As extracts a custom type, like os.PathError, into a variable. A red flag is using direct == or type assertions on wrapped errors.
Rust's operator equivalent to Go's if err != nil return err
Tests if you know Rust's ? operator for error propagation. A strong answer names ?, explains it returns Err from the function via Result's Try and FromResidual traits, and unwraps Ok. Red flag: calling it .unwrap() or suggesting manual match is idiomatic.
What are Rust Result's variants and how does the compiler enforce handling?
This tests Rust's explicit error model. A strong answer names Ok(T) and Err(E), explains must_use warns when Results are ignored, and notes pattern matching or ? is required to extract values.