tezvyn:

⚙️Backend Dev

Backend engineering, APIs, and databases

1085 bites

More in Backend Dev — page 46

Go & Rust2 min read

Go's GC: Low-Latency Collection with Tri-color Marking

Go's GC uses a tri-color algorithm to find unused memory concurrently, avoiding long pauses. It's crucial for low-latency services. The main footgun is breaking the invariant: a 'finished' (black) object must never point to a new (white) one without notifying…

GC vs. Ownership: Two Paths to Memory Safety
Go & Rust2 min read

GC vs. Ownership: Two Paths to Memory Safety

Rust's ownership model provides memory safety at compile-time, aiming for C++-level performance without a garbage collector. This makes it ideal for systems programming where resource control is key. The footgun is assuming all "safe" languages are equal.

Go & Rust2 min read

Rust's Lifetime Elision: When You Can Skip 'a

Lifetime elision lets you omit explicit lifetimes (`'a`) in function signatures. The compiler infers them from common patterns, like a function taking one reference and returning one.

Go & Rust2 min read

RAII in Rust: Automatic Cleanup via Scope

RAII ties a resource's lifetime to its owner's scope. When the owner variable is dropped, Rust automatically cleans up the resource, preventing leaks. This applies to heap memory, file handles, and locks. The footgun: cleanup is deterministic, not like a GC.

Go & Rust2 min read

Rust's `Drop` Trait: Automatic Resource Cleanup

Rust's `Drop` trait provides automatic, deterministic cleanup, like a destructor. It's used to release external resources like file handles or network sockets when a value goes out of scope. The key footgun: you cannot implement `Drop` on a `Copy` type.

Go & Rust2 min read

Rust's Copy Trait: Implicit Bitwise Duplication

Rust's `Copy` trait makes assignments duplicate a value instead of moving it, allowing the original to still be used. It's an implicit, bitwise copy for simple types like integers.

Go & Rust2 min read

Stack vs. Heap: Where Go Puts Your Data

The stack is a fast, last-in-first-out region for local, fixed-size data. The heap is slower, flexible memory for dynamic data or values that escape a function's scope.

Go & Rust2 min read

Rust Cargo Workspaces: A Monorepo Control Panel

A Cargo Workspace is a control panel for a multi-crate Rust project, unifying dependencies and build artifacts. Use it for related binaries and libraries to ensure consistent builds.

Go & Rust2 min read

Go's `internal` Directory: Private by Convention

Go's `internal` directory creates private packages within your module, making them inaccessible to external projects. Use it for helper logic you don't want to support as a public API.

Go & Rust2 min read

Rust's Module-to-Filesystem Mapping

Rust's module system maps directly to your file system. A `mod foo;` statement tells the compiler to look for `foo.rs` or `foo/mod.rs`. This is how you organize any multi-file Rust project.

Go & Rust2 min read

Cargo.toml: Rust's Project Recipe

Cargo.toml is your Rust project's recipe, telling the compiler what to build and what dependencies it needs. It defines metadata, production dependencies, and dev-only dependencies for testing.

Go & Rust2 min read

Rust Methods: Attaching Behavior to Data

Rust methods are functions attached to your data structures, defined in an `impl` block. Instead of `do_thing(my_struct)`, you call `my_struct.do_thing()`. The key footgun: `instance.name()` calls a method, but `instance.name` accesses a field.

Go & Rust2 min read

Rust Item Visibility: Private by Default

In Rust, all items are private by default. Think of modules as locked rooms; you need the `pub` keyword to unlock the door. This is crucial for creating a public API or letting modules interact.

Go & Rust2 min read

Go's Entry Point: The `main` Package and Function

A Go program's entry point is `package main`. The compiler finds this package and its `main()` function to create a runnable binary. The footgun is naming a library `main`; this name is reserved for executables and will cause build confusion.

Go & Rust2 min read

Rust Modules: Your Code's File System

Think of Rust modules as a file system for your code, grouping logic and hiding details. You declare them with `mod`, and Rust finds the code in corresponding files. The footgun: items are private by default, so you must use `pub` to expose them.

Go & Rust2 min read

Rust Crates: Your Unit of Compilation

A crate is the smallest unit of code the Rust compiler handles—either a runnable program (binary) or a shareable library. A package, defined by Cargo.toml, bundles one or more crates. The footgun: a package can have many binaries but only one library.

Go & Rust2 min read

Rust's Arc<T>: Share Data Ownership Across Threads

Rust's `Arc<T>` lets multiple threads share ownership of heap data. It's a smart pointer that counts references atomically. Use it for shared caches or config. The footgun: `Arc` only makes sharing safe, not mutation—you still need a `Mutex` for that.

Go & Rust2 min read

Rust's Rc<T>: Shared Ownership on a Single Thread

Rust's `Rc<T>` enables shared ownership within a single thread. Think of it as a counter on a heap-allocated resource: cloning an `Rc` increments the count, and the resource is freed only when the count hits zero. Use it for graph nodes with multiple owners.

Go & Rust2 min read

Go's sync.Map: A Specialized Concurrent Map

Go's `sync.Map` is a concurrent map optimized for keys written once and read many times. It's ideal for long-lived caches, but it's not a generic replacement for a map with a mutex. The footgun is using it for frequent writes, which can be slower.

Go & Rust2 min read

Rust Enums: Attaching Data Directly to Variants

A Rust enum variant can carry its own data, acting like a mini-struct. This is perfect for modeling states with different payloads, like a `Result` that holds either a value or an error. The footgun is using a separate struct to pair an enum with.