Logo
Logo
15 results for
  • Every Go program I’ve written has taught me the same lesson over and over: good code isn’t just about what you write inside functions — it’s about how you organize those functions in the first place. When I started with Go, I crammed everything into one file. It worked, until it didn’t. By the time I had a few hundred lines, I couldn’t find anything. That’s when packages stopped being an abstract concept and became something I genuinely needed.

    Go tutorial golang beginner Created Wed, 27 Mar 2024 00:00:00 +0000
  • Pattern matching ruined switch statements for me. After using match in Rust for a few months, going back to C-style switch/case feels like using a butter knife to do surgery. The compiler checks that you’ve covered every case. It destructures data inline. It does not fall through. It is, hands down, the most elegant control flow construct I’ve ever used.

    Basic match

    fn main() {
        let x = 3;
    
        match x {
            1 => println!("one"),
            2 => println!("two"),
            3 => println!("three"),
            _ => println!("something else"),
        }
    }
    

    _ is the catch-all pattern — it matches anything. Think of it as the default case in a switch statement, except it’s mandatory when the other arms don’t cover all possibilities.

    Rust tutorial rust beginner Created Tue, 26 Mar 2024 09:45:00 +0000
  • Tony Hoare called null his “billion-dollar mistake.” He invented it in 1965 and has publicly apologized for it multiple times since. Rust took him seriously. There is no null in Rust — and the replacement is so much better that going back to languages with null feels like giving up a superpower.

    Basic Enums

    At their simplest, enums define a type that can be one of several variants:

    #[derive(Debug)]
    enum Direction {
        North,
        South,
        East,
        West,
    }
    
    fn describe(dir: &Direction) -> &str {
        match dir {
            Direction::North => "heading north",
            Direction::South => "heading south",
            Direction::East => "heading east",
            Direction::West => "heading west",
        }
    }
    
    fn main() {
        let d = Direction::North;
        println!("{:?}: {}", d, describe(&d));
    }
    

    If this is all enums did, they’d be equivalent to C enums. Mildly useful. Not exciting.

    Rust tutorial rust beginner Created Mon, 25 Mar 2024 12:00:00 +0000
  • I worked on a Go codebase once where someone had passed around a map[string]interface{} for user data. It was fine until someone misspelled “email” as “emial” and we spent half a day tracking down why emails weren’t sending. Structs are how you prevent this entire category of mistake — named fields with typed data, checked at compile time.

    Defining a Struct

    struct User {
        name: String,
        email: String,
        age: u32,
        active: bool,
    }
    
    fn main() {
        let user = User {
            name: String::from("Alice"),
            email: String::from("alice@example.com"),
            age: 30,
            active: true,
        };
    
        println!("{} ({}) - age {}", user.name, user.email, user.age);
    }
    

    Struct names are PascalCase. Field names are snake_case. These aren’t suggestions — the compiler warns you if you deviate.

    Rust tutorial rust beginner Created Sat, 23 Mar 2024 20:15:00 +0000
  • Strings are the #1 source of confusion for Rust beginners. I see the same questions every week: “Why are there two string types?” “Why can’t I index a string?” “Why is this so much harder than in Python?” It’s not harder — it’s more honest. Other languages hide the complexity of text. Rust makes you deal with it.

    The Two String Types

    Rust has two main string types:

    • String — owned, heap-allocated, growable, mutable
    • &str — borrowed, a slice/view into string data, immutable (usually)
    fn main() {
        let owned: String = String::from("hello");  // heap-allocated, you own it
        let borrowed: &str = "hello";               // string literal, embedded in binary
    
        println!("{owned} {borrowed}");
    }
    

    The relationship between String and &str is exactly like Vec<u8> and &[u8]. A String is a buffer you own. A &str is a view into someone else’s string data (or a literal baked into your binary).

    Rust tutorial rust beginner Created Fri, 22 Mar 2024 15:30:00 +0000
  • By now you know how to create goroutines and how to communicate between them using channels. But what happens when a goroutine needs to listen to two channels at the same time? Maybe it’s waiting for work to arrive, but it also needs to stop if a timeout fires. With a single channel you’d be stuck — receiving from one blocks the other.

    select solves this. It’s like a switch statement for channels. It waits until one of several channel operations is ready, then executes that case. If multiple are ready at the same time, it picks one at random.

    Go tutorial golang beginner Created Fri, 22 Mar 2024 00:00:00 +0000
  • Slices clicked for me when I stopped thinking of them as a language feature and started thinking of them as a design pattern: “here’s a window into someone else’s data.” They’re one of Rust’s most elegant ideas, and you’ll use them everywhere.

    What Is a Slice?

    A slice is a reference to a contiguous sequence of elements in a collection. It doesn’t own the data — it’s a view into data owned by something else.

    Rust tutorial rust beginner Created Wed, 20 Mar 2024 10:45:00 +0000
  • After the last lesson, you might be thinking “so every function I call takes my data and I never see it again?” That would be terrible. Borrowing is the answer — it lets you share data without transferring ownership, and it’s where Rust’s safety guarantees really shine.

    References with &

    A reference lets you refer to a value without owning it:

    fn print_length(s: &String) {
        println!("Length of '{}': {}", s, s.len());
    }
    
    fn main() {
        let s = String::from("hello");
        print_length(&s);  // lend s to the function
        println!("I still own: {s}");  // s is still valid
    }
    

    The & creates a reference. &s doesn’t move s — it creates a pointer to s that the function can use. When the function returns, the reference goes away but s remains untouched.

    Rust tutorial rust beginner Created Mon, 18 Mar 2024 13:00:00 +0000
  • In the last lesson, I showed you how to run code concurrently with goroutines. But goroutines that can’t talk to each other aren’t very useful. What if one goroutine produces a result that another needs? What if you want to signal that work is done without using a WaitGroup? That’s where channels come in.

    Go’s guiding philosophy on concurrency is: “don’t communicate by sharing memory; share memory by communicating.” Channels are the mechanism for that. Instead of multiple goroutines reading and writing the same variable, they pass values through a channel — and the channel ensures only one goroutine handles the value at a time.

    Go tutorial golang beginner Created Mon, 18 Mar 2024 00:00:00 +0000
  • I spent three hours fighting the borrow checker on my first real Rust project. I was furious. Then I realized every single error the compiler flagged was a genuine bug — a use-after-free, a data race, a dangling reference. The compiler wasn’t being difficult. It was saving me from myself.

    Why Ownership Exists

    In C, you allocate memory and free it manually. Forget to free? Memory leak. Free twice? Undefined behavior. Use after free? Crash (if you’re lucky) or silent corruption (if you’re not).

    Rust tutorial rust beginner Created Sat, 16 Mar 2024 08:30:00 +0000