tezvyn:

Go & Rust

Go web services, Rust backends, systems programming

276 bites

More in Go & Rust — page 6

Go & Rust2 min read

How do you idiomatically return a recoverable error and result in Go?

This tests Go's multiple-return error idiom. A strong answer gives a (T, error) signature with error last, returns nil on success, and checks err before using the result. A red flag is suggesting panic for recoverable errors or pointer out-parameters.

Go & Rust2 min read

Rust unsafe FFI vs Cgo: who owns memory safety?

Tests your grasp of where compiler guarantees end at the FFI boundary. A strong answer contrasts Rust raw-pointer validity and aliasing invariants in unsafe blocks against Cgo's automatic copying, pointer-passing restrictions, and runtime thread-switching…

Go & Rust2 min read

Explain Rust Rc and Arc versus Go's tracing GC

This tests deterministic reference counting versus tracing GC. A strong answer contrasts Rc's heap reference counts with Go's root tracing, and notes Rc cannot reclaim cycles while Go's GC can. Red flag: claiming Rc has no cycle leak risk.

Go & Rust2 min read

Explain Go escape analysis and Rust ownership for stack vs heap

Tests compiler-driven memory placement. Go escape analysis keeps non-escaping locals on stack, shrinking heap and GC work. Rust ownership lets the compiler pick stack or heap at build time with zero cost. RED FLAG: Saying Go eliminates GC or Rust uses one.

Go & Rust2 min read

How does Rust ownership avoid Go GC's non-deterministic pauses?

Tests if you know Rust's compile-time ownership eliminates GC pauses by making deallocation deterministic at scope boundaries. A strong answer contrasts Go's STW with Rust's immediate Drop and zero-cost compile-time checks.

Go & Rust2 min read

Why are Rust's borrowing rules stricter than Go's pointers?

This tests compile-time versus runtime safety tradeoffs. A strong answer contrasts Go's aliasing with Rust's rule of one mutable or many immutable references to prevent data races without a GC. A red flag is calling Rust strict without citing race prevention.

Go & Rust2 min read

Explain Rust's Ownership and its three compiler-enforced rules

Tests your grasp of Rust's compile-time memory model. A strong answer lists the three ownership rules, links them to stack versus heap, and notes borrow checking enforces them at compile time. Red flag: calling it manual memory management.

Go & Rust2 min read

Describe Go's memory management, garbage collection, and trade-offs

WHAT IT TESTS: automatic memory management and stack versus heap division. ANSWER OUTLINE: explain Go's GC recycles heap memory, the compiler stack-allocates locals, and automatic collection costs runtime overhead.

Go & Rust2 min read

Explain the difference between mod and use in Rust

WHAT IT TESTS: declaration versus import in Rust's module system. ANSWER OUTLINE: mod tells the compiler to compile a file into the crate tree; use brings an existing path into scope as a shortcut.

Go & Rust2 min read

What is the purpose of the internal directory in Go?

Tests Go visibility boundaries beyond exported vs unexported. A strong answer states that internal is compiler-enforced module privacy, while lowercase is only package-private. Red flag: calling internal a naming convention rather than a build boundary.

Why does Go forbid circular dependencies, and how do you resolve them?
Go & Rust2 min read

Why does Go forbid circular dependencies, and how do you resolve them?

WHAT IT TESTS: Knowledge of Go's DAG package model. ANSWER OUTLINE: Cycles break incremental compilation; resolve by moving logic down, merging coupled packages, or using dependency injection. RED FLAG: Suggesting compiler workarounds over fixing design.

Go & Rust2 min read

Go package declaration, directory name, and import path relationship

Tests Go's separation of directory layout and package identity. A good answer states: import path is module path plus subdirectory; package clause is the in-code name; mismatch is legal and common for main or tests.

Go & Rust2 min read

How do Go and Rust control visibility of functions and types?

Tests encapsulation conventions in systems languages. Go uses capitalization: uppercase exports across packages; Rust uses explicit pub keywords with module-level privacy. Red flag: claiming either uses Java-style access modifiers or runtime visibility.

Go & Rust3 min read

Compare enum vs trait objects for heterogeneous shapes in Rust

This tests compile-time vs run-time polymorphism in Rust. A strong answer contrasts enum's closed set, static dispatch, and stack layout against trait objects' open extensibility, heap allocation, and vtable indirection.

Go & Rust2 min read

How does struct field ordering affect memory layout in Go and Rust?

It tests alignment, padding, and compiler layout knowledge. A strong answer explains that alignment inserts padding, Go and Rust keep declared order, and reordering by size can shrink size. Red flag: saying order is irrelevant or that compiler auto-packs.

Go & Rust2 min read

Explain Go struct embedding vs inheritance and method promotion

What it tests: knowing Go composition and method promotion from embeds. Outline: embedding adds a type as part without is-a; promoted methods join the outer type; collisions resolve by outer-type precedence.

Go & Rust2 min read

Sum Some values in Vec<Option<i32>>, ignoring None

Tests Rust Option handling and null-safety design. A strong answer uses map, unwrap_or, flatten, or match to skip Nones safely, and explains Option replaces null pointers with explicit enum variants. Red flag: using unwrap in a loop or suggesting null checks.

Go & Rust2 min read

What type replaces String for read-only function parameters in Rust?

WHAT IT TESTS: Knowledge of Rust's read-only string view and API ergonomics. ANSWER OUTLINE: Use &str; it borrows without ownership, accepts literals and String via coercion, and avoids clones.

Go & Rust2 min read

How do you safely share a Go map across goroutines?

Tests Go memory model. Answer: maps are not concurrency-safe and risk panic or corruption; use sync.RWMutex with map for read-heavy cases or sync.Map for cache-like patterns. Red flag: suggesting runtime.GOMAXPROCS or channel-only access without justification.

Go & Rust2 min read

Define a User struct and map of IDs to pointers

Tests Go struct and map pointer basics. Outline: define User with ID and Name, initialize map[int]*User with make, insert &User literals, and note shared mutation. Red flag: writing to a nil map or storing values instead of pointers.