<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Beginner on</title><link>/tags/beginner/</link><description>Recent content in Beginner on</description><generator>Hugo</generator><language>en</language><lastBuildDate>Sat, 11 May 2024 00:00:00 +0000</lastBuildDate><atom:link href="/tags/beginner/index.xml" rel="self" type="application/rss+xml"/><item><title>Lesson 25: What's Next — Your roadmap from beginner to production Go</title><link>/post/go/go-scratch-whats-next/</link><pubDate>Sat, 11 May 2024 00:00:00 +0000</pubDate><guid>/post/go/go-scratch-whats-next/</guid><description>&lt;p&gt;You made it. Twenty-five lessons ago you didn&amp;rsquo;t know what &lt;code&gt;package main&lt;/code&gt; meant. Now you understand variables, types, functions, error handling, interfaces, goroutines, testing, JSON, file I/O, the type system, and the entire toolchain. That is not beginner knowledge anymore.&lt;/p&gt;
&lt;p&gt;But there&amp;rsquo;s a gap between knowing the language and writing Go the way experienced Go developers write it. This lesson is about that gap — what it is, how to close it, and what to build while you do.&lt;/p&gt;</description></item><item><title>Lesson 24: The Go Toolchain — build, test, vet, fmt — your daily tools</title><link>/post/go/go-scratch-toolchain/</link><pubDate>Tue, 07 May 2024 00:00:00 +0000</pubDate><guid>/post/go/go-scratch-toolchain/</guid><description>&lt;p&gt;One of the things that drew me to Go was that the toolchain ships with the language. You don&amp;rsquo;t need to choose a build tool, a formatter, or a test framework — they&amp;rsquo;re all there from day one, and they&amp;rsquo;re all invoked the same way: &lt;code&gt;go &amp;lt;command&amp;gt;&lt;/code&gt;. This lesson is a tour of the tools you&amp;rsquo;ll use every single day.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id="the-basics"&gt;The Basics&lt;/h2&gt;
&lt;h3 id="go-run-and-go-build"&gt;go run and go build&lt;/h3&gt;
&lt;p&gt;You&amp;rsquo;ve used &lt;code&gt;go run&lt;/code&gt; throughout this course. It compiles your code and immediately executes it — perfect for development. Under the hood it creates a temporary binary and runs it, then throws the binary away.&lt;/p&gt;</description></item><item><title>Lesson 23: The Type System — Types, aliases, conversions, and embedding</title><link>/post/go/go-scratch-type-system/</link><pubDate>Thu, 02 May 2024 00:00:00 +0000</pubDate><guid>/post/go/go-scratch-type-system/</guid><description>&lt;p&gt;When I first came to Go from Python, the type system felt like a lot of ceremony. Why can&amp;rsquo;t I just use an &lt;code&gt;int&lt;/code&gt; where a &lt;code&gt;float64&lt;/code&gt; is expected? Why do I need to define a whole new type just to give an integer more meaning? The answers to those questions turned out to be one of the things I now appreciate most about Go. Types aren&amp;rsquo;t bureaucracy — they&amp;rsquo;re a way of making your code explain itself.&lt;/p&gt;</description></item><item><title>Lesson 22: File I/O — Reading and writing files the Go way</title><link>/post/go/go-scratch-files/</link><pubDate>Fri, 26 Apr 2024 00:00:00 +0000</pubDate><guid>/post/go/go-scratch-files/</guid><description>&lt;p&gt;At some point every program needs to persist something — a config file, a log, a data export. File I/O is one of those topics that sounds tedious but is genuinely satisfying once it clicks. Go gives you a few different layers to work with, from the low-level &lt;code&gt;os&lt;/code&gt; package to convenient one-liners. I&amp;rsquo;ll show you all of them so you can pick the right tool for the job.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id="the-basics"&gt;The Basics&lt;/h2&gt;
&lt;h3 id="reading-a-file-the-simple-way"&gt;Reading a file the simple way&lt;/h3&gt;
&lt;p&gt;For most cases where the file is small enough to fit in memory, &lt;code&gt;os.ReadFile&lt;/code&gt; is all you need:&lt;/p&gt;</description></item><item><title>Lesson 21: JSON and HTTP — Reading and writing the web's language</title><link>/post/go/go-scratch-json/</link><pubDate>Sun, 21 Apr 2024 00:00:00 +0000</pubDate><guid>/post/go/go-scratch-json/</guid><description>&lt;p&gt;Almost every program I write these days talks to something over HTTP — a third-party API, a database service, a webhook. And almost everything speaks JSON. So learning how Go handles JSON and HTTP isn&amp;rsquo;t an advanced topic; it&amp;rsquo;s one of the most practical skills you can pick up early.&lt;/p&gt;
&lt;p&gt;In this lesson I&amp;rsquo;ll walk you through converting Go structs to JSON and back, decoding JSON from an API response, and making real HTTP requests — all using only Go&amp;rsquo;s standard library. No third-party packages needed.&lt;/p&gt;</description></item><item><title>Lesson 25: Where to Go from Here — Your Rust learning path</title><link>/post/rust/rust-scratch-whats-next/</link><pubDate>Thu, 18 Apr 2024 18:00:00 +0000</pubDate><guid>/post/rust/rust-scratch-whats-next/</guid><description>&lt;p&gt;You&amp;rsquo;ve made it through 24 lessons. You understand ownership, borrowing, structs, enums, traits, generics, error handling, closures, iterators, and file I/O. That&amp;rsquo;s not nothing — that&amp;rsquo;s the foundation of every Rust program ever written. But foundations are for building on. Here&amp;rsquo;s where to go from here.&lt;/p&gt;
&lt;h2 id="what-you-know-now"&gt;What You Know Now&lt;/h2&gt;
&lt;p&gt;Take a second to appreciate what you&amp;rsquo;ve learned. You can:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Set up a Rust project with Cargo&lt;/li&gt;
&lt;li&gt;Write functions with proper ownership and borrowing&lt;/li&gt;
&lt;li&gt;Model data with structs and enums&lt;/li&gt;
&lt;li&gt;Handle errors with Result and the &lt;code&gt;?&lt;/code&gt; operator&lt;/li&gt;
&lt;li&gt;Use collections: Vec, HashMap, HashSet&lt;/li&gt;
&lt;li&gt;Write generic code with trait bounds&lt;/li&gt;
&lt;li&gt;Process data with iterators and closures&lt;/li&gt;
&lt;li&gt;Test your code with &lt;code&gt;#[test]&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Read and write files&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;That&amp;rsquo;s a real skill set. You can build useful things right now. Before diving into advanced topics, I strongly recommend you build something. Nothing fancy — a command-line tool, a file processor, a simple data structure. The gap between &amp;ldquo;I understand the concepts&amp;rdquo; and &amp;ldquo;I can write a program&amp;rdquo; is only bridged by practice.&lt;/p&gt;</description></item><item><title>Lesson 20: Testing in Go — Every Go file gets a test file</title><link>/post/go/go-scratch-testing/</link><pubDate>Wed, 17 Apr 2024 00:00:00 +0000</pubDate><guid>/post/go/go-scratch-testing/</guid><description>&lt;p&gt;I used to think testing was something you did after you finished writing code — a checkbox you ticked before committing. Go changed that attitude for me, not by lecturing me about best practices, but by making testing so straightforward that there was no excuse not to do it. The tooling is built in, the conventions are clear, and writing a test in Go takes about as long as writing the function itself. After a few weeks with Go, I started writing tests alongside my code, then slightly before it. The feedback loop became addictive.&lt;/p&gt;</description></item><item><title>Lesson 24: Reading and Writing Files — Real I/O in Rust</title><link>/post/rust/rust-scratch-file-io/</link><pubDate>Tue, 16 Apr 2024 13:45:00 +0000</pubDate><guid>/post/rust/rust-scratch-file-io/</guid><description>&lt;p&gt;Every tutorial teaches you to manipulate data in memory, but real programs read from files and write to files. Rust&amp;rsquo;s file I/O is built on the same ownership and error handling principles you&amp;rsquo;ve been learning — and once you see how &lt;code&gt;Result&lt;/code&gt;, iterators, and traits come together, the entire language design starts to feel cohesive.&lt;/p&gt;
&lt;h2 id="reading-a-file--the-quick-way"&gt;Reading a File — The Quick Way&lt;/h2&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-rust" data-lang="rust"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;use&lt;/span&gt; std::fs;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;fn&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;main&lt;/span&gt;() {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;match&lt;/span&gt; fs::read_to_string(&lt;span style="color:#e6db74"&gt;&amp;#34;hello.txt&amp;#34;&lt;/span&gt;) {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; Ok(content) &lt;span style="color:#f92672"&gt;=&amp;gt;&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;println!&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;File contents:&lt;/span&gt;&lt;span style="color:#ae81ff"&gt;\n&lt;/span&gt;&lt;span style="color:#e6db74"&gt;{content}&lt;/span&gt;&lt;span style="color:#e6db74"&gt;&amp;#34;&lt;/span&gt;),
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; Err(e) &lt;span style="color:#f92672"&gt;=&amp;gt;&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;eprintln!&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;Error reading file: &lt;/span&gt;&lt;span style="color:#e6db74"&gt;{e}&lt;/span&gt;&lt;span style="color:#e6db74"&gt;&amp;#34;&lt;/span&gt;),
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; }
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;code&gt;fs::read_to_string&lt;/code&gt; reads the entire file into a &lt;code&gt;String&lt;/code&gt;. It returns &lt;code&gt;Result&amp;lt;String, io::Error&amp;gt;&lt;/code&gt; — because file operations can fail (file doesn&amp;rsquo;t exist, permission denied, disk error, etc.).&lt;/p&gt;</description></item><item><title>Lesson 23: Writing Your First Tests — #[test] and assert!</title><link>/post/rust/rust-scratch-testing/</link><pubDate>Sun, 14 Apr 2024 11:00:00 +0000</pubDate><guid>/post/rust/rust-scratch-testing/</guid><description>&lt;p&gt;I have a rule: I won&amp;rsquo;t merge code without tests. Not because I&amp;rsquo;m a purist — because I&amp;rsquo;ve been burned too many times. Rust makes testing so frictionless that there&amp;rsquo;s no excuse to skip it. Tests live in the same file as your code. They run with one command. The tooling just works.&lt;/p&gt;
&lt;h2 id="your-first-test"&gt;Your First Test&lt;/h2&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-rust" data-lang="rust"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;fn&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;add&lt;/span&gt;(a: &lt;span style="color:#66d9ef"&gt;i32&lt;/span&gt;, b: &lt;span style="color:#66d9ef"&gt;i32&lt;/span&gt;) -&amp;gt; &lt;span style="color:#66d9ef"&gt;i32&lt;/span&gt; {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; a &lt;span style="color:#f92672"&gt;+&lt;/span&gt; b
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#75715e"&gt;#[cfg(test)]&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;mod&lt;/span&gt; tests {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;use&lt;/span&gt; &lt;span style="color:#66d9ef"&gt;super&lt;/span&gt;::&lt;span style="color:#f92672"&gt;*&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#75715e"&gt;#[test]&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;fn&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;test_add&lt;/span&gt;() {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#a6e22e"&gt;assert_eq!&lt;/span&gt;(add(&lt;span style="color:#ae81ff"&gt;2&lt;/span&gt;, &lt;span style="color:#ae81ff"&gt;3&lt;/span&gt;), &lt;span style="color:#ae81ff"&gt;5&lt;/span&gt;);
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; }
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#75715e"&gt;#[test]&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;fn&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;test_add_negative&lt;/span&gt;() {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#a6e22e"&gt;assert_eq!&lt;/span&gt;(add(&lt;span style="color:#f92672"&gt;-&lt;/span&gt;&lt;span style="color:#ae81ff"&gt;1&lt;/span&gt;, &lt;span style="color:#ae81ff"&gt;1&lt;/span&gt;), &lt;span style="color:#ae81ff"&gt;0&lt;/span&gt;);
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; }
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#75715e"&gt;#[test]&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;fn&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;test_add_zero&lt;/span&gt;() {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#a6e22e"&gt;assert_eq!&lt;/span&gt;(add(&lt;span style="color:#ae81ff"&gt;0&lt;/span&gt;, &lt;span style="color:#ae81ff"&gt;0&lt;/span&gt;), &lt;span style="color:#ae81ff"&gt;0&lt;/span&gt;);
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; }
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Run with &lt;code&gt;cargo test&lt;/code&gt;:&lt;/p&gt;</description></item><item><title>Lesson 22: Iterators — Lazy, composable data processing</title><link>/post/rust/rust-scratch-iterators/</link><pubDate>Fri, 12 Apr 2024 09:30:00 +0000</pubDate><guid>/post/rust/rust-scratch-iterators/</guid><description>&lt;p&gt;I once profiled a Go service and found it was spending 40% of CPU time allocating intermediate slices in a data pipeline. Each transformation created a new slice, copied data, processed it, then created another. In Rust, iterator chains do the same transformation with zero intermediate allocations. The data flows through the pipeline element by element, transformed in place. That&amp;rsquo;s not just elegant — it&amp;rsquo;s measurably faster.&lt;/p&gt;
&lt;h2 id="the-iterator-trait"&gt;The Iterator Trait&lt;/h2&gt;
&lt;p&gt;At its core, an iterator is any type that implements the &lt;code&gt;Iterator&lt;/code&gt; trait:&lt;/p&gt;</description></item><item><title>Lesson 19: Context — Passing deadlines and cancellation through your code</title><link>/post/go/go-scratch-context/</link><pubDate>Fri, 12 Apr 2024 00:00:00 +0000</pubDate><guid>/post/go/go-scratch-context/</guid><description>&lt;p&gt;There&amp;rsquo;s a moment in every Go developer&amp;rsquo;s journey when they realize that starting an operation isn&amp;rsquo;t the hard part — stopping it cleanly is. What happens when a user cancels a request? What happens when a database query takes 30 seconds instead of 300 milliseconds? Without a way to communicate &amp;ldquo;stop what you&amp;rsquo;re doing,&amp;rdquo; those goroutines keep running, consuming resources for something that no longer matters.&lt;/p&gt;
&lt;p&gt;That&amp;rsquo;s the problem &lt;code&gt;context&lt;/code&gt; solves. It gives you a standard way to carry a cancellation signal, a deadline, and a small amount of request-scoped data through your entire call stack. Once you understand it, you&amp;rsquo;ll see why the Go standard library passes it as the first parameter to almost every function that does I/O.&lt;/p&gt;</description></item><item><title>Lesson 21: Closures — Functions that capture</title><link>/post/rust/rust-scratch-closures/</link><pubDate>Wed, 10 Apr 2024 12:15:00 +0000</pubDate><guid>/post/rust/rust-scratch-closures/</guid><description>&lt;p&gt;Closures are where Rust stops feeling like a systems language and starts feeling like a functional one. You&amp;rsquo;ve already been using them — every time you passed &lt;code&gt;|x| x * 2&lt;/code&gt; to &lt;code&gt;.map()&lt;/code&gt; or &lt;code&gt;|a, b| a.cmp(b)&lt;/code&gt; to &lt;code&gt;.sort_by()&lt;/code&gt;, that was a closure. Time to understand what&amp;rsquo;s actually happening under the hood.&lt;/p&gt;
&lt;h2 id="what-is-a-closure"&gt;What Is a Closure?&lt;/h2&gt;
&lt;p&gt;A closure is an anonymous function that can capture variables from its surrounding scope:&lt;/p&gt;</description></item><item><title>Lesson 20: Generics — Writing code that works for any type</title><link>/post/rust/rust-scratch-generics-intro/</link><pubDate>Mon, 08 Apr 2024 20:00:00 +0000</pubDate><guid>/post/rust/rust-scratch-generics-intro/</guid><description>&lt;p&gt;I used to think generics were fancy academic stuff that you&amp;rsquo;d rarely need in practice. Then I wrote my third function that was identical to a previous one except it operated on &lt;code&gt;f64&lt;/code&gt; instead of &lt;code&gt;i32&lt;/code&gt;. Generics aren&amp;rsquo;t luxury features — they&amp;rsquo;re how you stop writing the same function five times for five different types.&lt;/p&gt;
&lt;h2 id="the-problem-generics-solve"&gt;The Problem Generics Solve&lt;/h2&gt;
&lt;p&gt;Without generics, you write duplicate code:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-rust" data-lang="rust"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;fn&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;largest_i32&lt;/span&gt;(list: &lt;span style="color:#66d9ef"&gt;&amp;amp;&lt;/span&gt;[&lt;span style="color:#66d9ef"&gt;i32&lt;/span&gt;]) -&amp;gt; &lt;span style="color:#66d9ef"&gt;&amp;amp;&lt;/span&gt;&lt;span style="color:#66d9ef"&gt;i32&lt;/span&gt; {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;let&lt;/span&gt; &lt;span style="color:#66d9ef"&gt;mut&lt;/span&gt; largest &lt;span style="color:#f92672"&gt;=&lt;/span&gt; &lt;span style="color:#f92672"&gt;&amp;amp;&lt;/span&gt;list[&lt;span style="color:#ae81ff"&gt;0&lt;/span&gt;];
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;for&lt;/span&gt; item &lt;span style="color:#66d9ef"&gt;in&lt;/span&gt; list {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;if&lt;/span&gt; item &lt;span style="color:#f92672"&gt;&amp;gt;&lt;/span&gt; largest {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; largest &lt;span style="color:#f92672"&gt;=&lt;/span&gt; item;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; }
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; }
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; largest
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;fn&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;largest_f64&lt;/span&gt;(list: &lt;span style="color:#66d9ef"&gt;&amp;amp;&lt;/span&gt;[&lt;span style="color:#66d9ef"&gt;f64&lt;/span&gt;]) -&amp;gt; &lt;span style="color:#66d9ef"&gt;&amp;amp;&lt;/span&gt;&lt;span style="color:#66d9ef"&gt;f64&lt;/span&gt; {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;let&lt;/span&gt; &lt;span style="color:#66d9ef"&gt;mut&lt;/span&gt; largest &lt;span style="color:#f92672"&gt;=&lt;/span&gt; &lt;span style="color:#f92672"&gt;&amp;amp;&lt;/span&gt;list[&lt;span style="color:#ae81ff"&gt;0&lt;/span&gt;];
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;for&lt;/span&gt; item &lt;span style="color:#66d9ef"&gt;in&lt;/span&gt; list {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;if&lt;/span&gt; item &lt;span style="color:#f92672"&gt;&amp;gt;&lt;/span&gt; largest {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; largest &lt;span style="color:#f92672"&gt;=&lt;/span&gt; item;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; }
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; }
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; largest
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;fn&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;main&lt;/span&gt;() {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;let&lt;/span&gt; ints &lt;span style="color:#f92672"&gt;=&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;vec!&lt;/span&gt;[&lt;span style="color:#ae81ff"&gt;34&lt;/span&gt;, &lt;span style="color:#ae81ff"&gt;50&lt;/span&gt;, &lt;span style="color:#ae81ff"&gt;25&lt;/span&gt;, &lt;span style="color:#ae81ff"&gt;100&lt;/span&gt;, &lt;span style="color:#ae81ff"&gt;65&lt;/span&gt;];
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;let&lt;/span&gt; floats &lt;span style="color:#f92672"&gt;=&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;vec!&lt;/span&gt;[&lt;span style="color:#ae81ff"&gt;3.4&lt;/span&gt;, &lt;span style="color:#ae81ff"&gt;5.0&lt;/span&gt;, &lt;span style="color:#ae81ff"&gt;2.5&lt;/span&gt;, &lt;span style="color:#ae81ff"&gt;10.0&lt;/span&gt;, &lt;span style="color:#ae81ff"&gt;6.5&lt;/span&gt;];
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#a6e22e"&gt;println!&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;Largest int: &lt;/span&gt;&lt;span style="color:#e6db74"&gt;{}&lt;/span&gt;&lt;span style="color:#e6db74"&gt;&amp;#34;&lt;/span&gt;, largest_i32(&lt;span style="color:#f92672"&gt;&amp;amp;&lt;/span&gt;ints));
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#a6e22e"&gt;println!&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;Largest float: &lt;/span&gt;&lt;span style="color:#e6db74"&gt;{}&lt;/span&gt;&lt;span style="color:#e6db74"&gt;&amp;#34;&lt;/span&gt;, largest_f64(&lt;span style="color:#f92672"&gt;&amp;amp;&lt;/span&gt;floats));
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;These functions are identical except for the type. Generics let you write it once:&lt;/p&gt;</description></item><item><title>Lesson 19: Traits — Your first abstraction</title><link>/post/rust/rust-scratch-traits-intro/</link><pubDate>Sun, 07 Apr 2024 15:45:00 +0000</pubDate><guid>/post/rust/rust-scratch-traits-intro/</guid><description>&lt;p&gt;Traits are the mechanism I miss most when I leave Rust. They&amp;rsquo;re interfaces without inheritance, type classes without the math, and the foundation of every abstraction in the language. If structs define what data &lt;em&gt;is&lt;/em&gt;, traits define what data &lt;em&gt;does&lt;/em&gt;.&lt;/p&gt;
&lt;h2 id="what-is-a-trait"&gt;What Is a Trait?&lt;/h2&gt;
&lt;p&gt;A trait defines a set of methods that a type can implement:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-rust" data-lang="rust"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;trait&lt;/span&gt; Greet {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;fn&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;hello&lt;/span&gt;(&lt;span style="color:#f92672"&gt;&amp;amp;&lt;/span&gt;self) -&amp;gt; String;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;struct&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;Person&lt;/span&gt; {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; name: String,
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;struct&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;Robot&lt;/span&gt; {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; id: &lt;span style="color:#66d9ef"&gt;u32&lt;/span&gt;,
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;impl&lt;/span&gt; Greet &lt;span style="color:#66d9ef"&gt;for&lt;/span&gt; Person {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;fn&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;hello&lt;/span&gt;(&lt;span style="color:#f92672"&gt;&amp;amp;&lt;/span&gt;self) -&amp;gt; String {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#a6e22e"&gt;format!&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;Hi, I&amp;#39;m &lt;/span&gt;&lt;span style="color:#e6db74"&gt;{}&lt;/span&gt;&lt;span style="color:#e6db74"&gt;!&amp;#34;&lt;/span&gt;, self.name)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; }
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;impl&lt;/span&gt; Greet &lt;span style="color:#66d9ef"&gt;for&lt;/span&gt; Robot {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;fn&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;hello&lt;/span&gt;(&lt;span style="color:#f92672"&gt;&amp;amp;&lt;/span&gt;self) -&amp;gt; String {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#a6e22e"&gt;format!&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;UNIT-&lt;/span&gt;&lt;span style="color:#e6db74"&gt;{}&lt;/span&gt;&lt;span style="color:#e6db74"&gt; OPERATIONAL&amp;#34;&lt;/span&gt;, self.id)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; }
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;fn&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;main&lt;/span&gt;() {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;let&lt;/span&gt; person &lt;span style="color:#f92672"&gt;=&lt;/span&gt; Person { name: String::from(&lt;span style="color:#e6db74"&gt;&amp;#34;Alice&amp;#34;&lt;/span&gt;) };
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;let&lt;/span&gt; robot &lt;span style="color:#f92672"&gt;=&lt;/span&gt; Robot { id: &lt;span style="color:#ae81ff"&gt;42&lt;/span&gt; };
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#a6e22e"&gt;println!&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;&lt;/span&gt;&lt;span style="color:#e6db74"&gt;{}&lt;/span&gt;&lt;span style="color:#e6db74"&gt;&amp;#34;&lt;/span&gt;, person.hello());
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#a6e22e"&gt;println!&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;&lt;/span&gt;&lt;span style="color:#e6db74"&gt;{}&lt;/span&gt;&lt;span style="color:#e6db74"&gt;&amp;#34;&lt;/span&gt;, robot.hello());
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The trait &lt;code&gt;Greet&lt;/code&gt; declares that any implementing type must have a &lt;code&gt;hello&lt;/code&gt; method. &lt;code&gt;Person&lt;/code&gt; and &lt;code&gt;Robot&lt;/code&gt; each provide their own implementation. Different types, same interface.&lt;/p&gt;</description></item><item><title>Lesson 18: The sync Package — Coordination tools for concurrent code</title><link>/post/go/go-scratch-sync/</link><pubDate>Sat, 06 Apr 2024 00:00:00 +0000</pubDate><guid>/post/go/go-scratch-sync/</guid><description>&lt;p&gt;Goroutines make concurrency easy to start, but easy to start isn&amp;rsquo;t the same as easy to get right. The first time I ran multiple goroutines that touched shared data, I got a data race — a situation where two goroutines read and write the same variable at the same time, producing unpredictable results. The Go race detector caught it immediately, but I still had to understand &lt;em&gt;how to fix it&lt;/em&gt;.&lt;/p&gt;</description></item><item><title>Lesson 18: Crates, Cargo.toml, and Dependencies — The Rust ecosystem</title><link>/post/rust/rust-scratch-crates/</link><pubDate>Fri, 05 Apr 2024 10:30:00 +0000</pubDate><guid>/post/rust/rust-scratch-crates/</guid><description>&lt;p&gt;The first time I added a dependency in Rust, I was shocked. Add one line to Cargo.toml, run &lt;code&gt;cargo build&lt;/code&gt;, and it downloads, compiles, and links everything automatically. Coming from C++ where dependency management is a special circle of hell, Cargo felt like cheating.&lt;/p&gt;
&lt;h2 id="what-is-a-crate"&gt;What Is a Crate?&lt;/h2&gt;
&lt;p&gt;A crate is a compilation unit in Rust — the smallest amount of code the compiler considers at a time. There are two kinds:&lt;/p&gt;</description></item><item><title>Lesson 17: Modules — Organizing your code</title><link>/post/rust/rust-scratch-modules/</link><pubDate>Wed, 03 Apr 2024 14:00:00 +0000</pubDate><guid>/post/rust/rust-scratch-modules/</guid><description>&lt;p&gt;Rust&amp;rsquo;s module system confused me for longer than I&amp;rsquo;d like to admit. I came from Go, where packages map directly to directories. Rust&amp;rsquo;s module system is more flexible — and more confusing as a result. But once you understand the mental model, it&amp;rsquo;s actually quite elegant. The key insight: the file system doesn&amp;rsquo;t define the module tree. You do.&lt;/p&gt;
&lt;h2 id="modules-in-a-single-file"&gt;Modules in a Single File&lt;/h2&gt;
&lt;p&gt;The simplest case — modules defined inline:&lt;/p&gt;</description></item><item><title>Lesson 17: Go Modules — Managing dependencies without pain</title><link>/post/go/go-scratch-modules/</link><pubDate>Tue, 02 Apr 2024 00:00:00 +0000</pubDate><guid>/post/go/go-scratch-modules/</guid><description>&lt;p&gt;Before Go modules existed, managing dependencies was genuinely painful. People used all sorts of third-party tools with their own conventions, and getting a new contributor up and running on a project could eat half a day. I started learning Go after modules became the standard, and I took for granted how smooth the experience was — until I read the old blog posts describing what came before. It made me appreciate &lt;code&gt;go mod init&lt;/code&gt; in a way that&amp;rsquo;s hard to describe.&lt;/p&gt;</description></item><item><title>Lesson 16: Result and the ? Operator — Errors as values</title><link>/post/rust/rust-scratch-error-handling/</link><pubDate>Mon, 01 Apr 2024 08:45:00 +0000</pubDate><guid>/post/rust/rust-scratch-error-handling/</guid><description>&lt;p&gt;Exception-based error handling has a fundamental flaw: you can&amp;rsquo;t tell by looking at a function signature whether it might throw. Go fixed this by returning &lt;code&gt;(value, error)&lt;/code&gt; tuples, but then you&amp;rsquo;re back to forgetting to check the error. Rust&amp;rsquo;s &lt;code&gt;Result&lt;/code&gt; type gets it right — errors are values, and the type system makes them impossible to ignore.&lt;/p&gt;
&lt;h2 id="the-result-type"&gt;The Result Type&lt;/h2&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-rust" data-lang="rust"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#75715e"&gt;// Built into the language:
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#75715e"&gt;// enum Result&amp;lt;T, E&amp;gt; {
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#75715e"&gt;// Ok(T),
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#75715e"&gt;// Err(E),
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#75715e"&gt;// }
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;code&gt;Result&amp;lt;T, E&amp;gt;&lt;/code&gt; is either &lt;code&gt;Ok(T)&lt;/code&gt; (success with a value) or &lt;code&gt;Err(E)&lt;/code&gt; (failure with an error). You&amp;rsquo;ve seen &lt;code&gt;Option&amp;lt;T&amp;gt;&lt;/code&gt; — &lt;code&gt;Result&lt;/code&gt; is similar but carries error information when something goes wrong.&lt;/p&gt;</description></item><item><title>Lesson 15: Vec, HashMap, and HashSet — The collections you'll use daily</title><link>/post/rust/rust-scratch-collections/</link><pubDate>Sat, 30 Mar 2024 11:15:00 +0000</pubDate><guid>/post/rust/rust-scratch-collections/</guid><description>&lt;p&gt;In my experience, about 80% of all data structures in real programs are either lists or key-value maps. Rust nails both of them. &lt;code&gt;Vec&lt;/code&gt; and &lt;code&gt;HashMap&lt;/code&gt; are fast, safe, and ergonomic — and once you know these two plus &lt;code&gt;HashSet&lt;/code&gt;, you can build almost anything.&lt;/p&gt;
&lt;h2 id="vec--the-dynamic-array"&gt;Vec — The Dynamic Array&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;Vec&amp;lt;T&amp;gt;&lt;/code&gt; is Rust&amp;rsquo;s growable array. It stores elements contiguously on the heap, like &lt;code&gt;ArrayList&lt;/code&gt; in Java or &lt;code&gt;std::vector&lt;/code&gt; in C++.&lt;/p&gt;</description></item><item><title>Lesson 14: Methods and Associated Functions — impl blocks explained</title><link>/post/rust/rust-scratch-methods/</link><pubDate>Thu, 28 Mar 2024 17:30:00 +0000</pubDate><guid>/post/rust/rust-scratch-methods/</guid><description>&lt;p&gt;In most object-oriented languages, data and behavior are bundled together inside classes. Rust separates them — you define data with &lt;code&gt;struct&lt;/code&gt; (or &lt;code&gt;enum&lt;/code&gt;) and attach behavior with &lt;code&gt;impl&lt;/code&gt; blocks. This separation is cleaner than it sounds. You can add methods to a type from anywhere, not just its original definition. And there&amp;rsquo;s no inheritance tax.&lt;/p&gt;
&lt;h2 id="your-first-impl-block"&gt;Your First impl Block&lt;/h2&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-rust" data-lang="rust"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#75715e"&gt;#[derive(Debug)]&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;struct&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;Rectangle&lt;/span&gt; {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; width: &lt;span style="color:#66d9ef"&gt;f64&lt;/span&gt;,
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; height: &lt;span style="color:#66d9ef"&gt;f64&lt;/span&gt;,
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;impl&lt;/span&gt; Rectangle {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;fn&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;area&lt;/span&gt;(&lt;span style="color:#f92672"&gt;&amp;amp;&lt;/span&gt;self) -&amp;gt; &lt;span style="color:#66d9ef"&gt;f64&lt;/span&gt; {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; self.width &lt;span style="color:#f92672"&gt;*&lt;/span&gt; self.height
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; }
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;fn&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;perimeter&lt;/span&gt;(&lt;span style="color:#f92672"&gt;&amp;amp;&lt;/span&gt;self) -&amp;gt; &lt;span style="color:#66d9ef"&gt;f64&lt;/span&gt; {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#ae81ff"&gt;2.0&lt;/span&gt; &lt;span style="color:#f92672"&gt;*&lt;/span&gt; (self.width &lt;span style="color:#f92672"&gt;+&lt;/span&gt; self.height)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; }
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;fn&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;is_square&lt;/span&gt;(&lt;span style="color:#f92672"&gt;&amp;amp;&lt;/span&gt;self) -&amp;gt; &lt;span style="color:#66d9ef"&gt;bool&lt;/span&gt; {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; (self.width &lt;span style="color:#f92672"&gt;-&lt;/span&gt; self.height).abs() &lt;span style="color:#f92672"&gt;&amp;lt;&lt;/span&gt; &lt;span style="color:#66d9ef"&gt;f64&lt;/span&gt;::&lt;span style="color:#66d9ef"&gt;EPSILON&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; }
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;fn&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;main&lt;/span&gt;() {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;let&lt;/span&gt; rect &lt;span style="color:#f92672"&gt;=&lt;/span&gt; Rectangle { width: &lt;span style="color:#ae81ff"&gt;10.0&lt;/span&gt;, height: &lt;span style="color:#ae81ff"&gt;5.0&lt;/span&gt; };
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#a6e22e"&gt;println!&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;Area: &lt;/span&gt;&lt;span style="color:#e6db74"&gt;{}&lt;/span&gt;&lt;span style="color:#e6db74"&gt;&amp;#34;&lt;/span&gt;, rect.area());
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#a6e22e"&gt;println!&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;Perimeter: &lt;/span&gt;&lt;span style="color:#e6db74"&gt;{}&lt;/span&gt;&lt;span style="color:#e6db74"&gt;&amp;#34;&lt;/span&gt;, rect.perimeter());
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#a6e22e"&gt;println!&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;Is square: &lt;/span&gt;&lt;span style="color:#e6db74"&gt;{}&lt;/span&gt;&lt;span style="color:#e6db74"&gt;&amp;#34;&lt;/span&gt;, rect.is_square());
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The &lt;code&gt;impl Rectangle&lt;/code&gt; block defines methods for the &lt;code&gt;Rectangle&lt;/code&gt; type. Inside the block, &lt;code&gt;&amp;amp;self&lt;/code&gt; is a reference to the instance the method is called on. It&amp;rsquo;s equivalent to &lt;code&gt;self: &amp;amp;Self&lt;/code&gt;, where &lt;code&gt;Self&lt;/code&gt; is an alias for &lt;code&gt;Rectangle&lt;/code&gt;.&lt;/p&gt;</description></item><item><title>Lesson 16: Packages and Imports — Organizing code like a professional</title><link>/post/go/go-scratch-packages/</link><pubDate>Wed, 27 Mar 2024 00:00:00 +0000</pubDate><guid>/post/go/go-scratch-packages/</guid><description>&lt;p&gt;Every Go program I&amp;rsquo;ve written has taught me the same lesson over and over: good code isn&amp;rsquo;t just about what you write inside functions — it&amp;rsquo;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&amp;rsquo;t. By the time I had a few hundred lines, I couldn&amp;rsquo;t find anything. That&amp;rsquo;s when packages stopped being an abstract concept and became something I genuinely needed.&lt;/p&gt;</description></item><item><title>Lesson 13: Pattern Matching — The match superpower</title><link>/post/rust/rust-scratch-pattern-matching/</link><pubDate>Tue, 26 Mar 2024 09:45:00 +0000</pubDate><guid>/post/rust/rust-scratch-pattern-matching/</guid><description>&lt;p&gt;Pattern matching ruined switch statements for me. After using &lt;code&gt;match&lt;/code&gt; 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&amp;rsquo;ve covered every case. It destructures data inline. It does not fall through. It is, hands down, the most elegant control flow construct I&amp;rsquo;ve ever used.&lt;/p&gt;
&lt;h2 id="basic-match"&gt;Basic match&lt;/h2&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-rust" data-lang="rust"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;fn&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;main&lt;/span&gt;() {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;let&lt;/span&gt; x &lt;span style="color:#f92672"&gt;=&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;3&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;match&lt;/span&gt; x {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#ae81ff"&gt;1&lt;/span&gt; &lt;span style="color:#f92672"&gt;=&amp;gt;&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;println!&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;one&amp;#34;&lt;/span&gt;),
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#ae81ff"&gt;2&lt;/span&gt; &lt;span style="color:#f92672"&gt;=&amp;gt;&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;println!&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;two&amp;#34;&lt;/span&gt;),
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#ae81ff"&gt;3&lt;/span&gt; &lt;span style="color:#f92672"&gt;=&amp;gt;&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;println!&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;three&amp;#34;&lt;/span&gt;),
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; _ &lt;span style="color:#f92672"&gt;=&amp;gt;&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;println!&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;something else&amp;#34;&lt;/span&gt;),
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; }
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;code&gt;_&lt;/code&gt; is the catch-all pattern — it matches anything. Think of it as the &lt;code&gt;default&lt;/code&gt; case in a switch statement, except it&amp;rsquo;s mandatory when the other arms don&amp;rsquo;t cover all possibilities.&lt;/p&gt;</description></item><item><title>Lesson 12: Enums and Option — Null safety by design</title><link>/post/rust/rust-scratch-enums/</link><pubDate>Mon, 25 Mar 2024 12:00:00 +0000</pubDate><guid>/post/rust/rust-scratch-enums/</guid><description>&lt;p&gt;Tony Hoare called null his &amp;ldquo;billion-dollar mistake.&amp;rdquo; 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.&lt;/p&gt;
&lt;h2 id="basic-enums"&gt;Basic Enums&lt;/h2&gt;
&lt;p&gt;At their simplest, enums define a type that can be one of several variants:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-rust" data-lang="rust"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#75715e"&gt;#[derive(Debug)]&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;enum&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;Direction&lt;/span&gt; {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; North,
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; South,
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; East,
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; West,
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;fn&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;describe&lt;/span&gt;(dir: &lt;span style="color:#66d9ef"&gt;&amp;amp;&lt;/span&gt;&lt;span style="color:#a6e22e"&gt;Direction&lt;/span&gt;) -&amp;gt; &lt;span style="color:#66d9ef"&gt;&amp;amp;&lt;/span&gt;&lt;span style="color:#66d9ef"&gt;str&lt;/span&gt; {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;match&lt;/span&gt; dir {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; Direction::North &lt;span style="color:#f92672"&gt;=&amp;gt;&lt;/span&gt; &lt;span style="color:#e6db74"&gt;&amp;#34;heading north&amp;#34;&lt;/span&gt;,
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; Direction::South &lt;span style="color:#f92672"&gt;=&amp;gt;&lt;/span&gt; &lt;span style="color:#e6db74"&gt;&amp;#34;heading south&amp;#34;&lt;/span&gt;,
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; Direction::East &lt;span style="color:#f92672"&gt;=&amp;gt;&lt;/span&gt; &lt;span style="color:#e6db74"&gt;&amp;#34;heading east&amp;#34;&lt;/span&gt;,
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; Direction::West &lt;span style="color:#f92672"&gt;=&amp;gt;&lt;/span&gt; &lt;span style="color:#e6db74"&gt;&amp;#34;heading west&amp;#34;&lt;/span&gt;,
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; }
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;fn&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;main&lt;/span&gt;() {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;let&lt;/span&gt; d &lt;span style="color:#f92672"&gt;=&lt;/span&gt; Direction::North;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#a6e22e"&gt;println!&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;&lt;/span&gt;&lt;span style="color:#e6db74"&gt;{:?}&lt;/span&gt;&lt;span style="color:#e6db74"&gt;: &lt;/span&gt;&lt;span style="color:#e6db74"&gt;{}&lt;/span&gt;&lt;span style="color:#e6db74"&gt;&amp;#34;&lt;/span&gt;, d, describe(&lt;span style="color:#f92672"&gt;&amp;amp;&lt;/span&gt;d));
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;If this is all enums did, they&amp;rsquo;d be equivalent to C enums. Mildly useful. Not exciting.&lt;/p&gt;</description></item><item><title>Lesson 11: Structs — Modeling your domain</title><link>/post/rust/rust-scratch-structs/</link><pubDate>Sat, 23 Mar 2024 20:15:00 +0000</pubDate><guid>/post/rust/rust-scratch-structs/</guid><description>&lt;p&gt;I worked on a Go codebase once where someone had passed around a &lt;code&gt;map[string]interface{}&lt;/code&gt; for user data. It was fine until someone misspelled &amp;ldquo;email&amp;rdquo; as &amp;ldquo;emial&amp;rdquo; and we spent half a day tracking down why emails weren&amp;rsquo;t sending. Structs are how you prevent this entire category of mistake — named fields with typed data, checked at compile time.&lt;/p&gt;
&lt;h2 id="defining-a-struct"&gt;Defining a Struct&lt;/h2&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-rust" data-lang="rust"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;struct&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;User&lt;/span&gt; {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; name: String,
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; email: String,
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; age: &lt;span style="color:#66d9ef"&gt;u32&lt;/span&gt;,
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; active: &lt;span style="color:#66d9ef"&gt;bool&lt;/span&gt;,
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;fn&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;main&lt;/span&gt;() {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;let&lt;/span&gt; user &lt;span style="color:#f92672"&gt;=&lt;/span&gt; User {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; name: String::from(&lt;span style="color:#e6db74"&gt;&amp;#34;Alice&amp;#34;&lt;/span&gt;),
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; email: String::from(&lt;span style="color:#e6db74"&gt;&amp;#34;alice@example.com&amp;#34;&lt;/span&gt;),
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; age: &lt;span style="color:#ae81ff"&gt;30&lt;/span&gt;,
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; active: &lt;span style="color:#a6e22e"&gt;true&lt;/span&gt;,
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; };
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#a6e22e"&gt;println!&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;&lt;/span&gt;&lt;span style="color:#e6db74"&gt;{}&lt;/span&gt;&lt;span style="color:#e6db74"&gt; (&lt;/span&gt;&lt;span style="color:#e6db74"&gt;{}&lt;/span&gt;&lt;span style="color:#e6db74"&gt;) - age &lt;/span&gt;&lt;span style="color:#e6db74"&gt;{}&lt;/span&gt;&lt;span style="color:#e6db74"&gt;&amp;#34;&lt;/span&gt;, user.name, user.email, user.age);
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Struct names are &lt;code&gt;PascalCase&lt;/code&gt;. Field names are &lt;code&gt;snake_case&lt;/code&gt;. These aren&amp;rsquo;t suggestions — the compiler warns you if you deviate.&lt;/p&gt;</description></item><item><title>Lesson 10: Strings — String vs &amp;str and why it matters</title><link>/post/rust/rust-scratch-strings/</link><pubDate>Fri, 22 Mar 2024 15:30:00 +0000</pubDate><guid>/post/rust/rust-scratch-strings/</guid><description>&lt;p&gt;Strings are the #1 source of confusion for Rust beginners. I see the same questions every week: &amp;ldquo;Why are there two string types?&amp;rdquo; &amp;ldquo;Why can&amp;rsquo;t I index a string?&amp;rdquo; &amp;ldquo;Why is this so much harder than in Python?&amp;rdquo; It&amp;rsquo;s not harder — it&amp;rsquo;s &lt;em&gt;more honest&lt;/em&gt;. Other languages hide the complexity of text. Rust makes you deal with it.&lt;/p&gt;
&lt;h2 id="the-two-string-types"&gt;The Two String Types&lt;/h2&gt;
&lt;p&gt;Rust has two main string types:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;String&lt;/code&gt;&lt;/strong&gt; — owned, heap-allocated, growable, mutable&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;&amp;amp;str&lt;/code&gt;&lt;/strong&gt; — borrowed, a slice/view into string data, immutable (usually)&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-rust" data-lang="rust"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;fn&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;main&lt;/span&gt;() {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;let&lt;/span&gt; owned: String &lt;span style="color:#f92672"&gt;=&lt;/span&gt; String::from(&lt;span style="color:#e6db74"&gt;&amp;#34;hello&amp;#34;&lt;/span&gt;); &lt;span style="color:#75715e"&gt;// heap-allocated, you own it
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;let&lt;/span&gt; borrowed: &lt;span style="color:#66d9ef"&gt;&amp;amp;&lt;/span&gt;&lt;span style="color:#66d9ef"&gt;str&lt;/span&gt; &lt;span style="color:#f92672"&gt;=&lt;/span&gt; &lt;span style="color:#e6db74"&gt;&amp;#34;hello&amp;#34;&lt;/span&gt;; &lt;span style="color:#75715e"&gt;// string literal, embedded in binary
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#a6e22e"&gt;println!&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;&lt;/span&gt;&lt;span style="color:#e6db74"&gt;{owned}&lt;/span&gt;&lt;span style="color:#e6db74"&gt; &lt;/span&gt;&lt;span style="color:#e6db74"&gt;{borrowed}&lt;/span&gt;&lt;span style="color:#e6db74"&gt;&amp;#34;&lt;/span&gt;);
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The relationship between &lt;code&gt;String&lt;/code&gt; and &lt;code&gt;&amp;amp;str&lt;/code&gt; is exactly like &lt;code&gt;Vec&amp;lt;u8&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;amp;[u8]&lt;/code&gt;. A &lt;code&gt;String&lt;/code&gt; is a buffer you own. A &lt;code&gt;&amp;amp;str&lt;/code&gt; is a view into someone else&amp;rsquo;s string data (or a literal baked into your binary).&lt;/p&gt;</description></item><item><title>Lesson 15: Select — Waiting on multiple channels at once</title><link>/post/go/go-scratch-select/</link><pubDate>Fri, 22 Mar 2024 00:00:00 +0000</pubDate><guid>/post/go/go-scratch-select/</guid><description>&lt;p&gt;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&amp;rsquo;s waiting for work to arrive, but it also needs to stop if a timeout fires. With a single channel you&amp;rsquo;d be stuck — receiving from one blocks the other.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;select&lt;/code&gt; solves this. It&amp;rsquo;s like a &lt;code&gt;switch&lt;/code&gt; 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.&lt;/p&gt;</description></item><item><title>Lesson 9: Slices — Views into data</title><link>/post/rust/rust-scratch-slices/</link><pubDate>Wed, 20 Mar 2024 10:45:00 +0000</pubDate><guid>/post/rust/rust-scratch-slices/</guid><description>&lt;p&gt;Slices clicked for me when I stopped thinking of them as a language feature and started thinking of them as a design pattern: &amp;ldquo;here&amp;rsquo;s a window into someone else&amp;rsquo;s data.&amp;rdquo; They&amp;rsquo;re one of Rust&amp;rsquo;s most elegant ideas, and you&amp;rsquo;ll use them everywhere.&lt;/p&gt;
&lt;h2 id="what-is-a-slice"&gt;What Is a Slice?&lt;/h2&gt;
&lt;p&gt;A slice is a reference to a contiguous sequence of elements in a collection. It doesn&amp;rsquo;t own the data — it&amp;rsquo;s a view into data owned by something else.&lt;/p&gt;</description></item><item><title>Lesson 8: Borrowing and References — Sharing without giving</title><link>/post/rust/rust-scratch-borrowing/</link><pubDate>Mon, 18 Mar 2024 13:00:00 +0000</pubDate><guid>/post/rust/rust-scratch-borrowing/</guid><description>&lt;p&gt;After the last lesson, you might be thinking &amp;ldquo;so every function I call takes my data and I never see it again?&amp;rdquo; That would be terrible. Borrowing is the answer — it lets you share data without transferring ownership, and it&amp;rsquo;s where Rust&amp;rsquo;s safety guarantees really shine.&lt;/p&gt;
&lt;h2 id="references-with-"&gt;References with &amp;amp;&lt;/h2&gt;
&lt;p&gt;A reference lets you refer to a value without owning it:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-rust" data-lang="rust"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;fn&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;print_length&lt;/span&gt;(s: &lt;span style="color:#66d9ef"&gt;&amp;amp;&lt;/span&gt;String) {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#a6e22e"&gt;println!&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;Length of &amp;#39;&lt;/span&gt;&lt;span style="color:#e6db74"&gt;{}&lt;/span&gt;&lt;span style="color:#e6db74"&gt;&amp;#39;: &lt;/span&gt;&lt;span style="color:#e6db74"&gt;{}&lt;/span&gt;&lt;span style="color:#e6db74"&gt;&amp;#34;&lt;/span&gt;, s, s.len());
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;fn&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;main&lt;/span&gt;() {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;let&lt;/span&gt; s &lt;span style="color:#f92672"&gt;=&lt;/span&gt; String::from(&lt;span style="color:#e6db74"&gt;&amp;#34;hello&amp;#34;&lt;/span&gt;);
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; print_length(&lt;span style="color:#f92672"&gt;&amp;amp;&lt;/span&gt;s); &lt;span style="color:#75715e"&gt;// lend s to the function
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#a6e22e"&gt;println!&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;I still own: &lt;/span&gt;&lt;span style="color:#e6db74"&gt;{s}&lt;/span&gt;&lt;span style="color:#e6db74"&gt;&amp;#34;&lt;/span&gt;); &lt;span style="color:#75715e"&gt;// s is still valid
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The &lt;code&gt;&amp;amp;&lt;/code&gt; creates a reference. &lt;code&gt;&amp;amp;s&lt;/code&gt; doesn&amp;rsquo;t move &lt;code&gt;s&lt;/code&gt; — it creates a pointer to &lt;code&gt;s&lt;/code&gt; that the function can use. When the function returns, the reference goes away but &lt;code&gt;s&lt;/code&gt; remains untouched.&lt;/p&gt;</description></item><item><title>Lesson 14: Channels — How goroutines talk to each other</title><link>/post/go/go-scratch-channels/</link><pubDate>Mon, 18 Mar 2024 00:00:00 +0000</pubDate><guid>/post/go/go-scratch-channels/</guid><description>&lt;p&gt;In the last lesson, I showed you how to run code concurrently with goroutines. But goroutines that can&amp;rsquo;t talk to each other aren&amp;rsquo;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 &lt;code&gt;WaitGroup&lt;/code&gt;? That&amp;rsquo;s where channels come in.&lt;/p&gt;
&lt;p&gt;Go&amp;rsquo;s guiding philosophy on concurrency is: &amp;ldquo;don&amp;rsquo;t communicate by sharing memory; share memory by communicating.&amp;rdquo; 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.&lt;/p&gt;</description></item><item><title>Lesson 7: Ownership — The rule that changes everything</title><link>/post/rust/rust-scratch-ownership/</link><pubDate>Sat, 16 Mar 2024 08:30:00 +0000</pubDate><guid>/post/rust/rust-scratch-ownership/</guid><description>&lt;p&gt;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&amp;rsquo;t being difficult. It was saving me from myself.&lt;/p&gt;
&lt;h2 id="why-ownership-exists"&gt;Why Ownership Exists&lt;/h2&gt;
&lt;p&gt;In C, you allocate memory and free it manually. Forget to free? Memory leak. Free twice? Undefined behavior. Use after free? Crash (if you&amp;rsquo;re lucky) or silent corruption (if you&amp;rsquo;re not).&lt;/p&gt;</description></item><item><title>Lesson 6: Control Flow — if, loop, while, for — and why there's no ternary</title><link>/post/rust/rust-scratch-control-flow/</link><pubDate>Thu, 14 Mar 2024 19:10:00 +0000</pubDate><guid>/post/rust/rust-scratch-control-flow/</guid><description>&lt;p&gt;I once reviewed a pull request that had seven levels of nested if-else. In Go. The author said &amp;ldquo;the language doesn&amp;rsquo;t give me better tools.&amp;rdquo; In Rust, you&amp;rsquo;ve got &lt;code&gt;match&lt;/code&gt;, labeled loops, &lt;code&gt;if let&lt;/code&gt;, and blocks-as-expressions — enough to keep your code flat and readable even when the logic is complex.&lt;/p&gt;
&lt;h2 id="if--else"&gt;if / else&lt;/h2&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-rust" data-lang="rust"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;fn&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;main&lt;/span&gt;() {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;let&lt;/span&gt; temperature &lt;span style="color:#f92672"&gt;=&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;35&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;if&lt;/span&gt; temperature &lt;span style="color:#f92672"&gt;&amp;gt;&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;30&lt;/span&gt; {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#a6e22e"&gt;println!&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;It&amp;#39;s hot&amp;#34;&lt;/span&gt;);
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; } &lt;span style="color:#66d9ef"&gt;else&lt;/span&gt; &lt;span style="color:#66d9ef"&gt;if&lt;/span&gt; temperature &lt;span style="color:#f92672"&gt;&amp;gt;&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;20&lt;/span&gt; {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#a6e22e"&gt;println!&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;It&amp;#39;s nice&amp;#34;&lt;/span&gt;);
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; } &lt;span style="color:#66d9ef"&gt;else&lt;/span&gt; {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#a6e22e"&gt;println!&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;It&amp;#39;s cold&amp;#34;&lt;/span&gt;);
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; }
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Standard stuff. No parentheses around the condition — that&amp;rsquo;s a syntax error in Rust. The braces are mandatory, even for single-line bodies. No arguing about whether to use braces. They&amp;rsquo;re required. Discussion over.&lt;/p&gt;</description></item><item><title>Lesson 5: Functions, Expressions, and Statements — Everything is an expression</title><link>/post/rust/rust-scratch-functions/</link><pubDate>Wed, 13 Mar 2024 10:20:00 +0000</pubDate><guid>/post/rust/rust-scratch-functions/</guid><description>&lt;p&gt;When I first read that &amp;ldquo;everything in Rust is an expression,&amp;rdquo; I thought it was marketing fluff. It&amp;rsquo;s not. It&amp;rsquo;s a genuine design principle that affects how you write code every single day, and once you internalize it, going back to statement-heavy languages feels clunky.&lt;/p&gt;
&lt;h2 id="defining-functions"&gt;Defining Functions&lt;/h2&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-rust" data-lang="rust"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;fn&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;add&lt;/span&gt;(a: &lt;span style="color:#66d9ef"&gt;i32&lt;/span&gt;, b: &lt;span style="color:#66d9ef"&gt;i32&lt;/span&gt;) -&amp;gt; &lt;span style="color:#66d9ef"&gt;i32&lt;/span&gt; {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; a &lt;span style="color:#f92672"&gt;+&lt;/span&gt; b
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;fn&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;main&lt;/span&gt;() {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;let&lt;/span&gt; result &lt;span style="color:#f92672"&gt;=&lt;/span&gt; add(&lt;span style="color:#ae81ff"&gt;3&lt;/span&gt;, &lt;span style="color:#ae81ff"&gt;7&lt;/span&gt;);
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#a6e22e"&gt;println!&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;3 + 7 = &lt;/span&gt;&lt;span style="color:#e6db74"&gt;{result}&lt;/span&gt;&lt;span style="color:#e6db74"&gt;&amp;#34;&lt;/span&gt;);
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;A few things to notice:&lt;/p&gt;</description></item><item><title>Lesson 13: Goroutines — Lightweight threads that cost almost nothing</title><link>/post/go/go-scratch-goroutines/</link><pubDate>Tue, 12 Mar 2024 00:00:00 +0000</pubDate><guid>/post/go/go-scratch-goroutines/</guid><description>&lt;p&gt;One of the first things people told me about Go was &amp;ldquo;it makes concurrency easy.&amp;rdquo; I was sceptical — concurrency is never easy. But the more I used goroutines, the more I understood what they meant. It&amp;rsquo;s not that concurrency becomes simple. It&amp;rsquo;s that the cost of starting a concurrent task drops so low that you stop avoiding it.&lt;/p&gt;
&lt;p&gt;In most languages, spawning a thread involves megabytes of stack memory and significant overhead. A Go goroutine starts with about 2KB of stack. You can run tens of thousands of them on a normal laptop without breaking a sweat.&lt;/p&gt;</description></item><item><title>Lesson 4: Variables, Mutability, and Primitive Types — Let, let mut, and the type system</title><link>/post/rust/rust-scratch-variables-types/</link><pubDate>Mon, 11 Mar 2024 16:45:00 +0000</pubDate><guid>/post/rust/rust-scratch-variables-types/</guid><description>&lt;p&gt;Coming from JavaScript, I was stunned the first time Rust refused to compile because I tried to reassign a variable. &amp;ldquo;What do you mean it&amp;rsquo;s immutable by default? Who designs a language like that?&amp;rdquo; Turns out — people who&amp;rsquo;ve debugged enough mutable state to know better.&lt;/p&gt;
&lt;h2 id="variables-with-let"&gt;Variables with let&lt;/h2&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-rust" data-lang="rust"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;fn&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;main&lt;/span&gt;() {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;let&lt;/span&gt; x &lt;span style="color:#f92672"&gt;=&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;5&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#a6e22e"&gt;println!&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;x is &lt;/span&gt;&lt;span style="color:#e6db74"&gt;{x}&lt;/span&gt;&lt;span style="color:#e6db74"&gt;&amp;#34;&lt;/span&gt;);
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;code&gt;let&lt;/code&gt; creates a variable binding. It binds a name to a value. By default, that binding is &lt;strong&gt;immutable&lt;/strong&gt; — you can&amp;rsquo;t change it.&lt;/p&gt;</description></item><item><title>Lesson 3: Hello, World — Anatomy of a Rust program</title><link>/post/rust/rust-scratch-first-program/</link><pubDate>Sat, 09 Mar 2024 11:00:00 +0000</pubDate><guid>/post/rust/rust-scratch-first-program/</guid><description>&lt;p&gt;The first program I ever wrote was in BASIC on a Commodore 64 emulator. Took me twenty minutes to figure out why PRINT didn&amp;rsquo;t work (I was typing PIRNT). Rust&amp;rsquo;s version of Hello World looks simple — four lines — but there&amp;rsquo;s a surprising amount of language design packed into those four lines.&lt;/p&gt;
&lt;h2 id="the-program"&gt;The Program&lt;/h2&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-rust" data-lang="rust"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;fn&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;main&lt;/span&gt;() {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#a6e22e"&gt;println!&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;Hello, world!&amp;#34;&lt;/span&gt;);
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;That&amp;rsquo;s it. Three lines if you&amp;rsquo;re counting. But each piece tells you something about how Rust thinks.&lt;/p&gt;</description></item><item><title>Lesson 2: Installing Rust — rustup, cargo, and your first build</title><link>/post/rust/rust-scratch-toolchain/</link><pubDate>Thu, 07 Mar 2024 14:30:00 +0000</pubDate><guid>/post/rust/rust-scratch-toolchain/</guid><description>&lt;p&gt;I&amp;rsquo;ve installed Rust on maybe fifty machines at this point — Linux servers, Macs, Windows boxes, even a Raspberry Pi. The process has gotten remarkably smooth. Rustup is one of the best toolchain managers in any language ecosystem, and I say that without hesitation.&lt;/p&gt;
&lt;h2 id="installing-rustup"&gt;Installing rustup&lt;/h2&gt;
&lt;p&gt;Rustup is the official Rust toolchain installer and manager. It handles downloading the compiler, updating it, and switching between versions. One command gets you everything.&lt;/p&gt;</description></item><item><title>Lesson 12: Error Handling — Errors are values, not exceptions</title><link>/post/go/go-scratch-errors/</link><pubDate>Wed, 06 Mar 2024 00:00:00 +0000</pubDate><guid>/post/go/go-scratch-errors/</guid><description>&lt;p&gt;The first time I wrote Go after years of Python and JavaScript, I kept waiting for the &lt;code&gt;try/catch&lt;/code&gt; block. It never came. Instead, almost every function returned two values: the result, and an error. I had to check the error every single time. It felt tedious at first. After a few weeks, I realised it was one of the best design decisions in the language.&lt;/p&gt;
&lt;p&gt;In Go, errors are just values. They&amp;rsquo;re not special. They don&amp;rsquo;t teleport up the call stack. They sit right there, in your return value, waiting for you to deal with them.&lt;/p&gt;</description></item><item><title>Lesson 1: Why Rust Exists — And why you should care</title><link>/post/rust/rust-scratch-why-rust/</link><pubDate>Tue, 05 Mar 2024 09:15:00 +0000</pubDate><guid>/post/rust/rust-scratch-why-rust/</guid><description>&lt;p&gt;I mass-deleted a production database once because a C program I&amp;rsquo;d written had a use-after-free bug that corrupted a pointer used for query routing. Took us fourteen hours to recover. That was the week I started learning Rust.&lt;/p&gt;
&lt;h2 id="the-problem-rust-solves"&gt;The Problem Rust Solves&lt;/h2&gt;
&lt;p&gt;Every few years, someone publishes a study on CVEs in major software projects. The numbers are always the same: roughly 70% of critical security vulnerabilities in C and C++ codebases are memory safety issues. Buffer overflows, use-after-free, double-free, null pointer dereferences. The same bugs, decade after decade.&lt;/p&gt;</description></item><item><title>Lesson 11: Interfaces — Contracts without the paperwork</title><link>/post/go/go-scratch-interfaces/</link><pubDate>Sat, 24 Feb 2024 00:00:00 +0000</pubDate><guid>/post/go/go-scratch-interfaces/</guid><description>&lt;p&gt;When I first learned about interfaces in Go, I expected something complicated — annotations, &lt;code&gt;implements&lt;/code&gt; keywords, class hierarchies. Instead, Go just asked: &amp;ldquo;does your type have the right methods?&amp;rdquo; That&amp;rsquo;s it. No paperwork. No explicit declaration. If your type does what the interface requires, it satisfies the interface automatically.&lt;/p&gt;
&lt;p&gt;This sounds small, but it changes how you design programs entirely.&lt;/p&gt;
&lt;h2 id="the-basics"&gt;The Basics&lt;/h2&gt;
&lt;p&gt;An interface in Go is a named set of method signatures. Any type that implements those methods automatically satisfies the interface. You don&amp;rsquo;t declare that you&amp;rsquo;re satisfying it. Go figures it out at compile time.&lt;/p&gt;</description></item><item><title>Lesson 10: Pointers — Addresses, not magic</title><link>/post/go/go-scratch-pointers/</link><pubDate>Sat, 17 Feb 2024 00:00:00 +0000</pubDate><guid>/post/go/go-scratch-pointers/</guid><description>&lt;p&gt;Pointers have a reputation for being scary. In C, they&amp;rsquo;re the source of buffer overflows, dangling references, and cryptic crashes. In Go, pointers are much tamer. There&amp;rsquo;s no pointer arithmetic, the garbage collector handles memory for you, and the rules are simpler. But pointers are still important — without them, you can&amp;rsquo;t write Go programs that mutate data through function calls, and you can&amp;rsquo;t use pointer receivers (which we covered in the last lesson).&lt;/p&gt;</description></item><item><title>Lesson 9: Methods — Functions that belong to a type</title><link>/post/go/go-scratch-methods/</link><pubDate>Sun, 11 Feb 2024 00:00:00 +0000</pubDate><guid>/post/go/go-scratch-methods/</guid><description>&lt;p&gt;In the last lesson we defined a &lt;code&gt;User&lt;/code&gt; struct. We could pass it to functions — &lt;code&gt;birthday(u)&lt;/code&gt;, &lt;code&gt;sendEmail(u)&lt;/code&gt;, &lt;code&gt;formatName(u)&lt;/code&gt;. That works, but there&amp;rsquo;s a better way: we can attach functions directly to the &lt;code&gt;User&lt;/code&gt; type. Then instead of &lt;code&gt;birthday(u)&lt;/code&gt; we write &lt;code&gt;u.Birthday()&lt;/code&gt;. Those are called methods.&lt;/p&gt;
&lt;p&gt;Methods make code more readable, more organized, and closer to how we naturally think about objects — &amp;ldquo;a user does birthday-related things&amp;rdquo; rather than &amp;ldquo;a birthday function takes a user.&amp;rdquo;&lt;/p&gt;</description></item><item><title>Lesson 8: Structs — Your first custom type</title><link>/post/go/go-scratch-structs/</link><pubDate>Wed, 07 Feb 2024 00:00:00 +0000</pubDate><guid>/post/go/go-scratch-structs/</guid><description>&lt;p&gt;So far we&amp;rsquo;ve been working with Go&amp;rsquo;s built-in types: strings, ints, booleans, slices, maps. Those are great, but real programs deal with real-world things — users, orders, products, messages. You need a way to group related data together and give it a meaningful name. In Go, that&amp;rsquo;s a struct.&lt;/p&gt;
&lt;p&gt;If you come from Python, think of a struct as a lightweight class that holds data (but with no inheritance, and methods are defined separately). If you come from JavaScript, think of it as a typed object. If you come from C, structs work almost exactly the same way.&lt;/p&gt;</description></item><item><title>Lesson 7: Strings, Runes, and Bytes — Strings aren't what you think</title><link>/post/go/go-scratch-strings/</link><pubDate>Fri, 02 Feb 2024 00:00:00 +0000</pubDate><guid>/post/go/go-scratch-strings/</guid><description>&lt;p&gt;Strings look simple. You write &lt;code&gt;&amp;quot;hello&amp;quot;&lt;/code&gt;, you print it, done. But when I first started working with non-ASCII text in Go — names with accents, emoji, Chinese characters — things started behaving oddly. &lt;code&gt;len(&amp;quot;café&amp;quot;)&lt;/code&gt; returned 5, not 4. Iterating with a regular index loop gave me garbled output. It took me a while to understand why, and once I did, a lot of things clicked.&lt;/p&gt;
&lt;p&gt;The short version: Go strings are sequences of bytes, not characters. Once you internalize that, the rest makes sense.&lt;/p&gt;</description></item><item><title>Lesson 6: Maps — Key-value pairs that power everything</title><link>/post/go/go-scratch-maps/</link><pubDate>Sat, 27 Jan 2024 00:00:00 +0000</pubDate><guid>/post/go/go-scratch-maps/</guid><description>&lt;p&gt;Every language has some version of the dictionary or hash map. Python calls it a &lt;code&gt;dict&lt;/code&gt;, JavaScript calls it an &lt;code&gt;Object&lt;/code&gt; or &lt;code&gt;Map&lt;/code&gt;, Ruby calls it a &lt;code&gt;Hash&lt;/code&gt;. In Go, it&amp;rsquo;s just called a map. Once you understand how Go maps work, you&amp;rsquo;ll reach for them constantly — they&amp;rsquo;re one of the most useful data structures in the language.&lt;/p&gt;
&lt;h2 id="the-basics"&gt;The Basics&lt;/h2&gt;
&lt;h3 id="creating-a-map"&gt;Creating a map&lt;/h3&gt;
&lt;p&gt;The zero value of a map is &lt;code&gt;nil&lt;/code&gt;. A nil map is readable (it returns zero values) but not writable. If you try to write to a nil map, your program panics. The safe way to create a map is with &lt;code&gt;make&lt;/code&gt;:&lt;/p&gt;</description></item><item><title>Lesson 5: Arrays and Slices — Slices are what you actually use</title><link>/post/go/go-scratch-arrays-slices/</link><pubDate>Mon, 22 Jan 2024 00:00:00 +0000</pubDate><guid>/post/go/go-scratch-arrays-slices/</guid><description>&lt;p&gt;Go has two sequence types: arrays and slices. I&amp;rsquo;ll tell you upfront — arrays are rarely used directly. They exist, they matter for understanding how things work under the hood, but in day-to-day Go programming you&amp;rsquo;ll almost always reach for a slice instead.&lt;/p&gt;
&lt;p&gt;Slices are Go&amp;rsquo;s workhorse collection type. They&amp;rsquo;re flexible, they grow when you need them to, and they&amp;rsquo;re used everywhere: in standard library APIs, in function parameters, in HTTP handlers. Understanding slices well will make you a much more effective Go programmer than memorizing syntax ever will.&lt;/p&gt;</description></item><item><title>Lesson 4: Functions — Small functions are Go's building blocks</title><link>/post/go/go-scratch-functions/</link><pubDate>Wed, 17 Jan 2024 00:00:00 +0000</pubDate><guid>/post/go/go-scratch-functions/</guid><description>&lt;p&gt;If there&amp;rsquo;s one thing experienced Go programmers agree on, it&amp;rsquo;s this: write small functions. Not tiny, cryptic one-liners, but focused functions that do one thing and are easy to test. Go&amp;rsquo;s function syntax encourages this style — it&amp;rsquo;s clean, explicit, and has one feature that&amp;rsquo;s genuinely different from most languages you&amp;rsquo;ve used before: multiple return values.&lt;/p&gt;
&lt;p&gt;In Python you can return a tuple. In JavaScript you can return an array. But in Go, returning two or three values is a first-class language feature with its own syntax, and it fundamentally changes how error handling works. By the end of this lesson you&amp;rsquo;ll understand Go functions well enough to start writing real, useful programs.&lt;/p&gt;</description></item><item><title>Lesson 3: Control Flow — if, for, and switch are all you need</title><link>/post/go/go-scratch-control-flow/</link><pubDate>Fri, 12 Jan 2024 00:00:00 +0000</pubDate><guid>/post/go/go-scratch-control-flow/</guid><description>&lt;p&gt;Every program you&amp;rsquo;ll ever write needs to make decisions and repeat actions. &amp;ldquo;If this condition is true, do that. Otherwise, do something else.&amp;rdquo; &amp;ldquo;Keep doing this until we run out of items.&amp;rdquo; These are the fundamental building blocks of logic, and Go handles them with just three constructs: &lt;code&gt;if&lt;/code&gt;, &lt;code&gt;for&lt;/code&gt;, and &lt;code&gt;switch&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;That&amp;rsquo;s it. No &lt;code&gt;while&lt;/code&gt;. No &lt;code&gt;do-while&lt;/code&gt;. No &lt;code&gt;foreach&lt;/code&gt; as a separate keyword. Go&amp;rsquo;s designers made a deliberate choice to keep the language small — fewer constructs means fewer ways to do the same thing, which means code is more consistent and easier to read across different projects and teams.&lt;/p&gt;</description></item><item><title>Lesson 2: Variables and Types — Go is typed, and that's a good thing</title><link>/post/go/go-scratch-variables-types/</link><pubDate>Mon, 08 Jan 2024 00:00:00 +0000</pubDate><guid>/post/go/go-scratch-variables-types/</guid><description>&lt;p&gt;If you&amp;rsquo;re coming from Python or JavaScript, Go&amp;rsquo;s type system might feel like extra work at first. Why should you have to tell the compiler that a variable holds a number? Can&amp;rsquo;t it just figure it out?&lt;/p&gt;
&lt;p&gt;Here&amp;rsquo;s the thing — it usually can. Go has type inference, so you rarely have to write out types explicitly. But when types &lt;em&gt;are&lt;/em&gt; written out, every person reading your code knows exactly what kind of data they&amp;rsquo;re dealing with. There&amp;rsquo;s no guessing, no surprises at runtime because a string snuck in where you expected a number. Go catches those mistakes at compile time, before your code ever runs.&lt;/p&gt;</description></item><item><title>Lesson 1: Your First Go Program — Hello World is just the beginning</title><link>/post/go/go-scratch-first-program/</link><pubDate>Wed, 03 Jan 2024 00:00:00 +0000</pubDate><guid>/post/go/go-scratch-first-program/</guid><description>&lt;p&gt;I remember the first time I ran a Go program. The compiler yelled at me for an unused import, and I thought, &amp;ldquo;Okay, this language has opinions.&amp;rdquo; That&amp;rsquo;s not a bad thing. Go&amp;rsquo;s strictness is part of what makes it so readable and maintainable. Once you understand &lt;em&gt;why&lt;/em&gt; Go works the way it does, it starts to feel less like friction and more like clarity.&lt;/p&gt;
&lt;p&gt;In this lesson you&amp;rsquo;re going to write your first Go program, understand every single line of it, and learn the basic tools you&amp;rsquo;ll use every day. By the end, &amp;ldquo;Hello, World!&amp;rdquo; won&amp;rsquo;t feel like a throwaway demo — it&amp;rsquo;ll feel like a foundation.&lt;/p&gt;</description></item></channel></rss>