Option<T> and Result<T>: No More Nil Pointers

    Go to Rust Series: ← String vs &str | Series Overview The Problem: Nil and Errors Tony Hoare (inventor of null references) called it his “billion-dollar mistake.” Go’s approach: nil values and explicit error returns Rust’s approach: Option<T> for absence, Result<T, E> for errors Go: Nil Pointers Go: func findUser(id int) *User { if id == 0 { return nil } return &User{ID: id, Name: "Alice"} } func main() { user := findUser(0) if user != nil { fmt.Println(user.Name) } else { fmt.Println("User not found") } } Problem: Easy to forget nil check: ...

    April 29, 2025 · 8 min · Rafiul Alam

    String vs &str: Rust's Confusing String Types for Go Devs

    Go to Rust Series: ← Mut vs Immutable | Series Overview | Option and Result → The Confusion Go has one string type: var s string = "hello" Rust has two main string types: let s1: String = String::from("hello"); // Owned string let s2: &str = "hello"; // String slice Why two types? It’s one of the most confusing aspects for Go developers learning Rust. Go: One String Type Go: package main import "fmt" func main() { // All of these are just "string" s1 := "hello" s2 := "world" s3 := s1 + " " + s2 printString(s1) printString(s3) } func printString(s string) { fmt.Println(s) } Simple. Everything is string. ...

    April 26, 2025 · 7 min · Rafiul Alam

    Mut vs Immutable: Why Rust Makes You Choose

    Go to Rust Series: ← Lifetimes Explained | Series Overview | String vs &str → The Default Difference Go: Everything is mutable by default Rust: Everything is immutable by default This single difference shapes how you write code in each language. Go: Mutable by Default Go: func main() { x := 10 x = 20 // No problem x = x + 5 // No problem fmt.Println(x) // 25 } Variables are mutable unless you use const (which is very limited): const PI = 3.14 // Compile-time constant only PI = 3.14159 // Error Rust: Immutable by Default Rust: ...

    April 25, 2025 · 7 min · Rafiul Alam

    Lifetimes Explained: The Annotation Go Developers Never Needed

    Go to Rust Series: ← No Garbage Collector | Series Overview | Mut vs Immutable → The Concept Go Doesn’t Need Lifetimes are Rust’s way of tracking how long references are valid-all at compile time. Go doesn’t need lifetimes because the garbage collector tracks reference validity at runtime. Rust needs them because there’s no GC. Go: References Just Work Go: func getFirst(a, b string) string { if len(a) > len(b) { return a } return b } func main() { x := "short" y := "longer" result := getFirst(x, y) fmt.Println(result) } No annotations needed. GC ensures result stays valid. ...

    April 24, 2025 · 7 min · Rafiul Alam

    No Garbage Collector: How Rust Manages Memory Without GC

    Go to Rust Series: ← Ownership and Borrowing | Series Overview | Lifetimes Explained → The Fundamental Trade-Off Go: Automatic memory management via garbage collection Rust: Compile-time memory management via ownership Both approaches have profound implications for performance, predictability, and developer experience. How Go’s GC Works Go: func allocateData() { for i := 0; i < 1000000; i++ { data := make([]byte, 1024) // Use data... // No explicit free needed } } Go’s GC: Tracks all allocations Periodically stops the world (STW) Scans for reachable objects Frees unreachable memory GC pause times: Typically 1-10ms, but can spike higher. ...

    April 23, 2025 · 7 min · Rafiul Alam

    Ownership and Borrowing: The Concept Go Doesn't Have

    Go to Rust Series: ← The Rust Compiler | Series Overview | No Garbage Collector → The Core Difference Ownership is Rust’s most important concept-and the one Go completely lacks. In Go, the garbage collector handles memory. In Rust, the ownership system handles memory at compile time, with zero runtime cost. Go’s Approach: Share and GC Go: package main import "fmt" func main() { data := []int{1, 2, 3} // Pass to multiple functions printData(data) modifyData(data) printData(data) // Still usable fmt.Println(data) } func printData(d []int) { fmt.Println(d) } func modifyData(d []int) { d[0] = 999 // Modifies original } Output: ...

    April 22, 2025 · 7 min · Rafiul Alam

    The Rust Compiler: Why It Yells at You (And Go Doesn't)

    Go to Rust Series: ← Setting Up Rust | Series Overview | Ownership and Borrowing → The First Encounter Week 1 with Go: I shipped features. Week 1 with Rust: I fought the compiler. This isn’t a bug-it’s Rust’s design. The compiler is strict, verbose, and often frustrating. But after fighting it for weeks, I realized: it’s actually trying to help me. Compiler Philosophy Go: Trust the Developer Go’s compiler does basic checks and gets out of your way: ...

    April 19, 2025 · 9 min · Rafiul Alam

    Setting Up Rust: Tooling Compared to Go's Simplicity

    Go to Rust Series: ← Hello World Comparison | Series Overview | The Rust Compiler → Installation: First Impressions Go: Download and Done Installation: Go to golang.org/dl Download installer for your OS Run installer Done Verify: $ go version go version go1.22.0 linux/amd64 That’s it. Go is installed. One binary, one version, ready to use. Where it lives: $ which go /usr/local/go/bin/go Single installation directory. Simple. Rust: The Rustup Way Installation: $ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh This installs rustup, Rust’s toolchain manager (like nvm for Node or rbenv for Ruby). ...

    April 18, 2025 · 8 min · Rafiul Alam

    Hello World in Rust: Why It's More Complex Than Go

    Go to Rust Series: ← Cargo vs Go Modules | Series Overview | Setting Up Rust → The “Simple” Hello World Every programming tutorial starts with “Hello, World!” It’s supposed to be trivial. But comparing Go and Rust versions reveals fundamental philosophical differences. Go’s Hello World main.go: package main import "fmt" func main() { fmt.Println("Hello, World!") } Compile and run: go run main.go Output: Hello, World! Done. Five lines. Zero surprises. Rust’s Hello World main.rs: ...

    April 17, 2025 · 7 min · Rafiul Alam

    Cargo vs Go Modules: Package Management Face-Off

    Go to Rust Series: ← Day 1 Impressions | Series Overview | Hello World Comparison → First Impression: Cargo is Actually Great After struggling with Rust’s ownership system on Day 1, I expected the tooling to be equally complex. I was wrong. Cargo is fantastic. Coming from Go modules (which are already pretty good), Cargo feels like a spiritual successor with better UX. Project Initialization Go: mkdir myproject cd myproject go mod init github.com/username/myproject Creates go.mod: ...

    April 16, 2025 · 9 min · Rafiul Alam