More in Go & Rust — page 14
Rust's Turbofish (`::<>`): When the Compiler Needs Help
The turbofish (`::<>`) is your tool to resolve ambiguity when Rust's compiler can't infer a type or trait. Use it when a type implements multiple traits with same-named methods, forcing the compiler to pick the one you specify.
Rust's Variable Shadowing: Re-binding, Not Mutating
Shadowing lets you declare a new variable with the same name, making the old one inaccessible. It's used to transform a value, like changing its type, without making it mutable. The footgun is confusing shadowing (`let x = ...`) with reassignment (`x = ...`).
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.
Zero-Cost Abstractions: Pay at Compile Time, Not Runtime
Zero-cost abstractions let you write high-level code that compiles to the same machine code as low-level optimizations. This is key in Rust for safe APIs without runtime overhead.
Rust's Two Error Types: Recoverable vs. Unrecoverable
Rust splits errors into two camps: recoverable (`Result`) and unrecoverable (`panic!`). This compile-time distinction forces you to handle expected failures, like a missing file, while crashing on programmer bugs, like an out-of-bounds access.

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.
Rust Traits: Defining Shared Behavior
Rust traits are like contracts that guarantee a type has certain methods, similar to interfaces. This lets you write functions that operate on any type with that behavior, like a `summarize` method for both articles and posts.
Rust's Borrow Checker: Memory Safety at Compile Time
Rust's borrow checker is a compiler-time accountant that prevents memory bugs by enforcing ownership rules. It ensures you never access invalid data or have conflicting writes. The main footgun is assuming references are mutable by default; they aren't.
Rust Ownership: Memory Safety Without a Garbage Collector
Rust's ownership model ensures memory safety without a garbage collector. Think of data as having one owner; when the owner goes out of scope, the data is dropped.
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.
Rust's Philosophy: Documentation and Community First
Rust's philosophy is deeply tied to its learning resources and community, ensuring developers are well-supported. This is evident in its official book, which is bundled with the language installation itself.
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.