<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Stanley Chege Thuita</title>
    <description>The latest articles on DEV Community by Stanley Chege Thuita (@altradits).</description>
    <link>https://dev.to/altradits</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3924446%2F58a31d80-504c-4e12-9f39-02882b10d8fa.png</url>
      <title>DEV Community: Stanley Chege Thuita</title>
      <link>https://dev.to/altradits</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/altradits"/>
    <language>en</language>
    <item>
      <title>We built TerraTrend Observatory for NASA Space Apps 2026: is this place really changing?</title>
      <dc:creator>Stanley Chege Thuita</dc:creator>
      <pubDate>Sun, 15 Nov 2026 15:46:54 +0000</pubDate>
      <link>https://dev.to/altradits/we-built-terratrend-observatory-for-nasa-space-apps-2026-is-this-place-really-changing-499h</link>
      <guid>https://dev.to/altradits/we-built-terratrend-observatory-for-nasa-space-apps-2026-is-this-place-really-changing-499h</guid>
      <description>&lt;p&gt;We just submitted &lt;strong&gt;TerraTrend Observatory&lt;/strong&gt; to the 2026 NASA Space Apps Challenge as Team GreenGen, from Kisumu, Kenya. This post covers what we built, how the statistics work, what was hard, and what we would do next.&lt;/p&gt;

&lt;h2&gt;
  
  
  The challenge
&lt;/h2&gt;

&lt;p&gt;Our challenge was &lt;strong&gt;"Be An Earth System Trend Detective!"&lt;/strong&gt;. Build a tool that picks Earth science variables, shows how they change over time, and answers four questions: &lt;strong&gt;what&lt;/strong&gt; is changing, &lt;strong&gt;where&lt;/strong&gt;, &lt;strong&gt;how much&lt;/strong&gt;, and whether the change is &lt;strong&gt;significant&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Climate arguments often end in anecdotes: one hot year, one late rainy season. NASA holds decades of observations, but most students, journalists, teachers and local planners never touch scientific APIs. We wanted a three-step tool: pick a place, pick what to track, read the finding.&lt;/p&gt;

&lt;h2&gt;
  
  
  What it does
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Search for a city, a feature or coordinates, or click anywhere on a NASA Blue Marble world map.&lt;/li&gt;
&lt;li&gt;Pick one of six variables. All six are live NASA POWER data: Earth skin temperature, precipitation, surface albedo, soil moisture, 10 m wind speed and solar irradiance (from MERRA-2, CERES and GPM-based products).&lt;/li&gt;
&lt;li&gt;Get a verdict badge, a trend chart and a plain-words explanation.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Example from the live app: &lt;strong&gt;Utqiagvik, Alaska&lt;/strong&gt; skin temperature rose about &lt;strong&gt;+0.58 °C per decade&lt;/strong&gt; from 1985 to 2024 (p &amp;lt; 0.001, 95% CI 0.40 to 0.76). Mann-Kendall agrees, with a Sen's slope of +0.47 °C per decade.&lt;/p&gt;

&lt;h2&gt;
  
  
  How the statistics work
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Fetch.&lt;/strong&gt; An Express server requests 40 years (1985-2024, 480 months) of monthly point data from the NASA POWER API. It caches responses for 30 minutes and serves recorded live data, clearly labeled, if NASA is unreachable.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Deseasonalize.&lt;/strong&gt; We subtract each calendar month's average, so the chart shows long-term drift instead of summer-versus-winter swings.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Two tests must agree.&lt;/strong&gt; We fit an ordinary least-squares trend with a 95% confidence band and p-value, then cross-check with the non-parametric Mann-Kendall test and Sen's slope.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Explain.&lt;/strong&gt; A plain-words panel turns the numbers into sentences. It also states that R² can be small while a trend is real, and that a trend is not a cause.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Honest limits
&lt;/h2&gt;

&lt;p&gt;Every result shows its source label. NASA POWER gives gridded reanalysis and satellite-derived estimates for a point, not a ground-station reading. Significance is evidence under the tests we used, not proof of a cause.&lt;/p&gt;

&lt;h2&gt;
  
  
  What was hard
&lt;/h2&gt;

&lt;p&gt;The hackathon weekend overlapped with &lt;strong&gt;Kisumu Market Day&lt;/strong&gt;, where I was also taking part, so a lot of my coding happened late at night. We also had to cut scope. The repo has a 3D globe, region comparison and a satellite image wipe, but we shipped a simpler dashboard so the deployed app would be reliable before the deadline.&lt;/p&gt;

&lt;h2&gt;
  
  
  Tools
&lt;/h2&gt;

&lt;p&gt;TypeScript, React 19, Vite, Tailwind CSS, SVG charts, Node.js with Express, the NASA POWER API, NASA GIBS imagery and Open-Meteo geocoding. We wrote the statistics ourselves and cover them with a science test suite. The app is deployed on Render.&lt;/p&gt;

&lt;h2&gt;
  
  
  Links
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Live app: &lt;a href="https://earth-science-trend-observatory.onrender.com/" rel="noopener noreferrer"&gt;https://earth-science-trend-observatory.onrender.com/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Demo slides (7): &lt;a href="https://github.com/altradits/terratrend-greengen-demo" rel="noopener noreferrer"&gt;https://github.com/altradits/terratrend-greengen-demo&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Code: &lt;a href="https://github.com/Christian3788/Earth-Science-Trend-Observatory" rel="noopener noreferrer"&gt;https://github.com/Christian3788/Earth-Science-Trend-Observatory&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Team and thanks
&lt;/h2&gt;

&lt;p&gt;Built by Team GreenGen: Victor Ouma (team owner), Stanley Chege Thuita, Hellen Onyango, Jack Omosh, Chepkorir Miriam Chemeres and Christian Amos Otieno. Thank you to NASA Space Apps Challenge, and a shout-out to the Kisumu tech community at Zone01 Kisumu and LakeHub.&lt;/p&gt;

&lt;p&gt;I also received my participant certificate: Galactic Problem Solver. 🌍&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Some of this post and the demo slide text were drafted with AI assistance; the numbers and screenshots come from the live app.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>nasa</category>
      <category>hackathon</category>
      <category>opendata</category>
      <category>react</category>
    </item>
    <item>
      <title>Away from the keyboard: Kisumu Market Day</title>
      <dc:creator>Stanley Chege Thuita</dc:creator>
      <pubDate>Fri, 13 Nov 2026 18:42:55 +0000</pubDate>
      <link>https://dev.to/altradits/away-from-the-keyboard-kisumu-market-day-9dm</link>
      <guid>https://dev.to/altradits/away-from-the-keyboard-kisumu-market-day-9dm</guid>
      <description>&lt;p&gt;Most of my posts here are about code: the Bitcoin Lightning wallet I build from Kisumu, Kenya, and what I learn reviewing Bitcoin's code.&lt;/p&gt;

&lt;p&gt;Today I stepped away from the keyboard for Kisumu Market Day at Baraza Media Lab: two days of the city's creators, makers and storytellers under one roof, opening with a photo exhibition about Lake Victoria.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://www.tiktok.com/@altradits/video/7707724995190869261" rel="noopener noreferrer"&gt;Watch the 30-second walk-through on TikTok&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Why a developer goes to a market day: the people building things here are the people my tools are for. Meeting them in person teaches me more about what they need than any issue tracker.&lt;/p&gt;

&lt;p&gt;If you're in Kisumu, it's on tomorrow (Sat 14 Nov), 8:30am to 7pm, Lake Basin Mall. Say hi.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Not sponsored.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>watercooler</category>
      <category>community</category>
      <category>kenya</category>
      <category>bitcoin</category>
    </item>
    <item>
      <title>One day, nine updates: making a Bitcoin wallet in Kisumu reliable</title>
      <dc:creator>Stanley Chege Thuita</dc:creator>
      <pubDate>Fri, 13 Nov 2026 03:37:04 +0000</pubDate>
      <link>https://dev.to/altradits/one-day-nine-updates-making-a-bitcoin-wallet-in-kisumu-reliable-128l</link>
      <guid>https://dev.to/altradits/one-day-nine-updates-making-a-bitcoin-wallet-in-kisumu-reliable-128l</guid>
      <description>&lt;p&gt;I build &lt;strong&gt;Ye₿ente&lt;/strong&gt;, an open-source Bitcoin Lightning wallet, here in Kisumu, Kenya. It runs on my own Lightning node, and it can pay any shop in kTown, a small network of local shops that take bitcoin and get paid in M-Pesa.&lt;/p&gt;

&lt;p&gt;Today's work was about one thing: when someone taps &lt;strong&gt;Send&lt;/strong&gt;, the money should actually go. Nine pull requests later, here is what changed and what I learned.&lt;/p&gt;

&lt;p&gt;  &lt;iframe src="https://www.youtube.com/embed/OH4OYROf1YM" width="710" height="399"&gt;
  &lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Sends were refused while the node was healthy
&lt;/h2&gt;

&lt;p&gt;Users saw &lt;em&gt;"Sending is paused while the wallet reconnects."&lt;/em&gt; The node was fine: synced, one active channel. So why?&lt;/p&gt;

&lt;p&gt;Before every send, the server asks the node how much it can send. That read used the &lt;strong&gt;pay key&lt;/strong&gt;, and the pay key could pay but couldn't read channel balances. The answer came back blank, and a blank meant "node unreachable", so every send was refused.&lt;/p&gt;

&lt;p&gt;The fix: reads fall back to the node's &lt;strong&gt;read-only key&lt;/strong&gt;. Neither key can move money through these calls.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Reads about sending (channels, payments): the pay key first,&lt;/span&gt;
&lt;span class="c1"&gt;// then the read-only key.&lt;/span&gt;
&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;readForPay&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;opts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;keys&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;YEBENTE_LND_PAY_MACAROON&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;READ&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Boolean&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;last&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"No node key can read this."&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;macaroon&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="n"&gt;keys&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;lndRequest&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"GET"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;opts&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;macaroon&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;last&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="n"&gt;last&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The new test fails on the old code with the exact error users saw, and passes with the fix. A security review checked the change before merge. (&lt;a href="https://github.com/altradits/altradits/pull/495" rel="noopener noreferrer"&gt;PR #495&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lesson:&lt;/strong&gt; least privilege is right, but test the &lt;em&gt;reads&lt;/em&gt; your code depends on with the exact key it will use in production.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Never show "sent" for a payment that didn't go
&lt;/h2&gt;

&lt;p&gt;When the node didn't answer in time, the server replied "pending", and the app still played the &lt;em&gt;sent&lt;/em&gt; animation. Now a pending payment shows &lt;strong&gt;"Not confirmed yet"&lt;/strong&gt;, no celebration, and if it fails the sats come back. (&lt;a href="https://github.com/altradits/altradits/pull/491" rel="noopener noreferrer"&gt;PR #491&lt;/a&gt;)&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Paying kTown shop QR codes
&lt;/h2&gt;

&lt;p&gt;A kTown QR is an LNURL on our own domain (&lt;code&gt;/.well-known/lnurlp/k-&amp;lt;id&amp;gt;&lt;/code&gt;). The wallet saw its own domain and read &lt;code&gt;k-&amp;lt;id&amp;gt;&lt;/code&gt; as a wallet name: &lt;em&gt;"No Ye₿ente wallet has that handle."&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Now &lt;code&gt;k-&lt;/code&gt; means a shop, and the wallet asks kTown for the shop's invoice directly. Going over HTTP to ourselves would have failed anyway: kTown fronts the payout partner, so the invoice commits to the partner's description, not kTown's. New wallets can't take a &lt;code&gt;k-&lt;/code&gt; name, so none can pose as a shop. (&lt;a href="https://github.com/altradits/altradits/pull/493" rel="noopener noreferrer"&gt;PR #493&lt;/a&gt;)&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Send and Receive, simpler
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Send opens on the scanner&lt;/strong&gt;: continuous focus, tap to focus, torch and zoom where the phone has them, and every other frame a sharp close-up of the middle for small or dense codes. (&lt;a href="https://github.com/altradits/altradits/pull/501" rel="noopener noreferrer"&gt;PR #501&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Clipboard offer&lt;/strong&gt;: copy an invoice or Lightning address and the app offers to paste it. It's read on the phone only, used only if you tap Paste.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Approve last&lt;/strong&gt;: no PIN box on the amount screen. Send opens your fingerprint, or a final PIN pop-up. (&lt;a href="https://github.com/altradits/altradits/pull/503" rel="noopener noreferrer"&gt;PR #503&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Receive is one big QR&lt;/strong&gt; with your address under it, one tap to copy, and an invoice that fills the screen until it's paid. (&lt;a href="https://github.com/altradits/altradits/pull/505" rel="noopener noreferrer"&gt;PR #505&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No empty wallet&lt;/strong&gt;: while the node reconnects, the buttons stay on screen, greyed out. (&lt;a href="https://github.com/altradits/altradits/pull/489" rel="noopener noreferrer"&gt;PR #489&lt;/a&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  How it ships
&lt;/h2&gt;

&lt;p&gt;Every change gets an issue, a pull request, tests that fail on the old code first, CI, and a review before merge. The suite is at &lt;strong&gt;779 tests&lt;/strong&gt; passing. It's all public: &lt;a href="https://github.com/altradits/altradits" rel="noopener noreferrer"&gt;github.com/altradits/altradits&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I'm working toward full-time Bitcoin open-source work, learning to review Bitcoin's code alongside building this.&lt;/p&gt;

&lt;p&gt;Not sponsored. No paid posts. Try the wallet: &lt;a href="https://altradits.com/yebente" rel="noopener noreferrer"&gt;altradits.com/yebente&lt;/a&gt;&lt;/p&gt;

</description>
      <category>bitcoin</category>
      <category>opensource</category>
      <category>javascript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>8 shops in 5 days, then a new chapter: learning Bitcoin open source in public</title>
      <dc:creator>Stanley Chege Thuita</dc:creator>
      <pubDate>Thu, 12 Nov 2026 15:01:13 +0000</pubDate>
      <link>https://dev.to/altradits/8-shops-in-5-days-then-a-new-chapter-learning-bitcoin-open-source-in-public-3dm0</link>
      <guid>https://dev.to/altradits/8-shops-in-5-days-then-a-new-chapter-learning-bitcoin-open-source-in-public-3dm0</guid>
      <description>&lt;p&gt;I set out to bring one Kisumu merchant onto bitcoin every week. Between 8 and 12 November 2026, eight said yes.&lt;/p&gt;

&lt;p&gt;That was the kTown pilot. This post closes it, thanks everyone who made it possible, and opens the next chapter: learning Bitcoin open source in public.&lt;/p&gt;


&lt;div&gt;
    &lt;iframe src="https://www.youtube.com/embed/Fb2N7TFfd3c" width="315" height="560"&gt;
    &lt;/iframe&gt;
  &lt;/div&gt;


&lt;h2&gt;
  
  
  The pilot: 8 shops in 5 days
&lt;/h2&gt;

&lt;p&gt;kTown is a QR code that lets any shop take bitcoin. A customer pays in sats from any Lightning wallet and the shop receives shillings on M-Pesa. Nothing changes at the till.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;#&lt;/th&gt;
&lt;th&gt;Shop&lt;/th&gt;
&lt;th&gt;Type&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;01&lt;/td&gt;
&lt;td&gt;Mama Jobu Hotel&lt;/td&gt;
&lt;td&gt;physical&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;02&lt;/td&gt;
&lt;td&gt;Kisumu Explorers&lt;/td&gt;
&lt;td&gt;online, run by Zone01 Kisumu students&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;03&lt;/td&gt;
&lt;td&gt;Austine Kicks&lt;/td&gt;
&lt;td&gt;online, run by a Zone01 Kisumu student&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;04&lt;/td&gt;
&lt;td&gt;Lake Basin Mall Hotel&lt;/td&gt;
&lt;td&gt;physical&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;05&lt;/td&gt;
&lt;td&gt;Mall Café&lt;/td&gt;
&lt;td&gt;physical&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;06&lt;/td&gt;
&lt;td&gt;Debs Beauty Hub&lt;/td&gt;
&lt;td&gt;physical&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;07&lt;/td&gt;
&lt;td&gt;Judphil Cyber&lt;/td&gt;
&lt;td&gt;physical&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;08&lt;/td&gt;
&lt;td&gt;Edu Shop&lt;/td&gt;
&lt;td&gt;physical&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The six physical shops each got a QR poster: designed, printed, hot-press laminated so it survives rain, flour and busy hands, and carried across town to the counter. The two online shops use digital QR codes for now, because the first phase needed physical shops.&lt;/p&gt;

&lt;p&gt;Each poster cost me about &lt;strong&gt;$1&lt;/strong&gt;. Merchants paid nothing. I had no sponsor and made no paid posts. At the physical shops I paid first with my own sats, so every owner saw the shillings arrive.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Thank you&lt;/strong&gt; to every one of these shops. You took a chance on something new, and you move Kisumu's economy forward every day.&lt;/p&gt;

&lt;p&gt;Earlier stories: &lt;a href="https://dev.to/altradits/a-1-qr-code-that-lets-kisumu-shops-take-bitcoin-and-get-m-pesa-35fk"&gt;shops 1–2&lt;/a&gt; · &lt;a href="https://dev.to/altradits/shop-no-4-takes-bitcoin-in-kisumu-now-i-need-people-who-earn-it-285j"&gt;shop 4&lt;/a&gt; · &lt;a href="https://dev.to/altradits/pov-youre-qr-no-5-mall-cafe-in-kisumu-now-takes-bitcoin-1o6"&gt;shop 5&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What the pilot taught me
&lt;/h2&gt;

&lt;p&gt;Shops are ready. Every owner was amazed that it works and asked why more people don't use it.&lt;/p&gt;

&lt;p&gt;The missing half is the spender. Kisumu needs people who &lt;strong&gt;earn&lt;/strong&gt; bitcoin, and local builders who make tools for local businesses. Posters can't fix that. Skills can.&lt;/p&gt;

&lt;h2&gt;
  
  
  The next chapter: open source
&lt;/h2&gt;

&lt;p&gt;I'm now concentrating on open-source skills: learning to review the code that powers bitcoin, alongside my apprenticeship, so I can contribute to open source full time.&lt;/p&gt;

&lt;p&gt;My goal is a &lt;strong&gt;Btrust Starter Grant to work full time on LND&lt;/strong&gt;, the Lightning Network Daemon. The bar is clear: at least five merged code pull requests on one project, careful reviews of other people's work, help in the community, a six-month plan, and two people on the project who vouch for me.&lt;/p&gt;

&lt;h3&gt;
  
  
  Day 4 of 234
&lt;/h3&gt;

&lt;p&gt;I follow a Builder Path: one verified deliverable a day, from 9 November 2026 to the 2027 grant window. Every day is proven by my public GitHub activity. Nothing is ticked by hand. Today is &lt;strong&gt;day 4 of 234&lt;/strong&gt;, in the foundations phase.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Nov–Dec:&lt;/strong&gt; foundations (Git, the terminal, enough Go to read LND, enough C++ to build and test Bitcoin Core), and apply to BOSS or a Builders pathway when it opens.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Jan–Feb:&lt;/strong&gt; tested reviews every week.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Feb–Apr:&lt;/strong&gt; issues and small pull requests, with feedback from two mentors.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Apr–Jun:&lt;/strong&gt; merged pull requests, a proposal and the application.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;My week: Monday to Friday, the day's task. Saturday: reflect, do one lab drill, and teach one merchant, so kTown keeps growing. Sunday: rest.&lt;/p&gt;

&lt;h3&gt;
  
  
  Where I'm learning
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;LND&lt;/strong&gt; (lightningnetwork/lnd), my focus&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Bitcoin Core&lt;/strong&gt; (bitcoin/bitcoin), through the PR Review Club&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Bitcoin Dev Kit&lt;/strong&gt; (bitcoindevkit/bdk)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;BOLTs&lt;/strong&gt; (lightning/bolts)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Bitcoin Optech&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Bitcoin Design Guide&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I've already shipped &lt;strong&gt;24 merged pull requests&lt;/strong&gt; to Minmo's &lt;a href="https://github.com/minmoto/payment-channels" rel="noopener noreferrer"&gt;payment-channels&lt;/a&gt;, including African payment corridor schemas.&lt;/p&gt;

&lt;h3&gt;
  
  
  My lab
&lt;/h3&gt;

&lt;p&gt;A Mac running Bitcoin Core and LND built from source, regtest and signet nodes to break things safely, and a small Lightning node on mainnet. Regtest first, signet next, mainnet last and small.&lt;/p&gt;

&lt;h3&gt;
  
  
  The honest part
&lt;/h3&gt;

&lt;p&gt;The hard thing right now is understanding a large codebase, reading pull requests and testing them properly. My review routine is simple: build the change, run its tests, try to break it on regtest, read what others already said, then post exactly what I ran and what I saw. Ask, don't guess.&lt;/p&gt;

&lt;p&gt;It's slow at first. We all start somewhere.&lt;/p&gt;

&lt;h2&gt;
  
  
  How you can help
&lt;/h2&gt;

&lt;p&gt;I'm open to &lt;strong&gt;any&lt;/strong&gt; open-source project as I build these skills.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Collaborate:&lt;/strong&gt; building on bitcoin or Lightning? Let's build together.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Sponsor:&lt;/strong&gt; support my open-source time and the next kTown shops in sats: &lt;a href="https://altradits.com/donate.html" rel="noopener noreferrer"&gt;https://altradits.com/donate.html&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Mentor or review:&lt;/strong&gt; point me to good first issues, or review my work.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Invite me in:&lt;/strong&gt; if you maintain a repo with good first issues, docs to test, or pull requests that need careful reviewers, I'll show up, test, and report honestly.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Have a shop?&lt;/strong&gt; Register free: &lt;a href="https://altradits.com/ktown/" rel="noopener noreferrer"&gt;https://altradits.com/ktown/&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Follow all 234 days: &lt;a href="https://altradits.com/tracker/" rel="noopener noreferrer"&gt;https://altradits.com/tracker/&lt;/a&gt; · GitHub: &lt;a href="https://github.com/altradits" rel="noopener noreferrer"&gt;https://github.com/altradits&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Not sponsored. No paid posts.&lt;/p&gt;

&lt;h2&gt;
  
  
  Watch and follow
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;YouTube Short: &lt;a href="https://youtube.com/shorts/Fb2N7TFfd3c" rel="noopener noreferrer"&gt;https://youtube.com/shorts/Fb2N7TFfd3c&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;X thread (pinned): &lt;a href="https://x.com/altradits/status/2120895675642650858" rel="noopener noreferrer"&gt;https://x.com/altradits/status/2120895675642650858&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;LinkedIn: &lt;a href="https://www.linkedin.com/posts/stanmobitech_bitcoin-opensource-lightning-ugcPost-7526662109925928961-O1fp/" rel="noopener noreferrer"&gt;https://www.linkedin.com/posts/stanmobitech_bitcoin-opensource-lightning-ugcPost-7526662109925928961-O1fp/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Facebook: &lt;a href="https://www.facebook.com/reel/1163783359433214" rel="noopener noreferrer"&gt;https://www.facebook.com/reel/1163783359433214&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Instagram Reel: &lt;a href="https://www.instagram.com/reel/DfpWKJzBJca/" rel="noopener noreferrer"&gt;https://www.instagram.com/reel/DfpWKJzBJca/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;TikTok: &lt;a href="https://www.tiktok.com/@altradits/video/7707302878850960654" rel="noopener noreferrer"&gt;https://www.tiktok.com/@altradits/video/7707302878850960654&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>bitcoin</category>
      <category>opensource</category>
      <category>lightning</category>
      <category>career</category>
    </item>
    <item>
      <title>POV: you're QR no. 5. Mall Café in Kisumu now takes bitcoin</title>
      <dc:creator>Stanley Chege Thuita</dc:creator>
      <pubDate>Thu, 12 Nov 2026 13:33:22 +0000</pubDate>
      <link>https://dev.to/altradits/pov-youre-qr-no-5-mall-cafe-in-kisumu-now-takes-bitcoin-1o6</link>
      <guid>https://dev.to/altradits/pov-youre-qr-no-5-mall-cafe-in-kisumu-now-takes-bitcoin-1o6</guid>
      <description>&lt;p&gt;This time the QR tells the story.&lt;/p&gt;

&lt;p&gt;Shop no. 5 is &lt;strong&gt;Mall Café&lt;/strong&gt; in Kisumu. Its poster came off the printer, went through the hot press so it survives a busy café, crossed town under a moody sky, and went up at the counter.&lt;/p&gt;


&lt;div&gt;
    &lt;iframe src="https://www.youtube.com/embed/m2-UT59vYEQ" width="315" height="560"&gt;
    &lt;/iframe&gt;
  &lt;/div&gt;


&lt;h2&gt;
  
  
  Five shops in five days
&lt;/h2&gt;

&lt;p&gt;I set out to onboard one merchant a week. Since 8 November we've onboarded five.&lt;/p&gt;

&lt;p&gt;Each shop gets kTown: a QR that takes bitcoin from any Lightning wallet and pays the shop in shillings on M-Pesa. No new app, no exchange account, nothing new at the till.&lt;/p&gt;

&lt;h2&gt;
  
  
  What it costs
&lt;/h2&gt;

&lt;p&gt;Each laminated poster costs me about $1. Merchants pay nothing. I have no sponsor, so I fund it myself, including the sats I spend paying at each shop so the owner sees it work.&lt;/p&gt;

&lt;p&gt;I've now applied for grants so kTown can keep going without depending on my pocket.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to help
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Run a shop?&lt;/strong&gt; Register free: &lt;a href="https://altradits.com/ktown/" rel="noopener noreferrer"&gt;https://altradits.com/ktown/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Sponsor the next shop or donate sats:&lt;/strong&gt; &lt;a href="https://altradits.com/donate.html" rel="noopener noreferrer"&gt;https://altradits.com/donate.html&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Know work that pays in sats?&lt;/strong&gt; Kisumu needs people who earn bitcoin, not just shops that accept it.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Shop no. 4's story: &lt;a href="https://dev.to/altradits/shop-no-4-takes-bitcoin-in-kisumu-now-i-need-people-who-earn-it-285j"&gt;https://dev.to/altradits/shop-no-4-takes-bitcoin-in-kisumu-now-i-need-people-who-earn-it-285j&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Watch and follow
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;YouTube Short: &lt;a href="https://youtube.com/shorts/m2-UT59vYEQ" rel="noopener noreferrer"&gt;https://youtube.com/shorts/m2-UT59vYEQ&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;X: &lt;a href="https://x.com/altradits/status/2120873144672231705" rel="noopener noreferrer"&gt;https://x.com/altradits/status/2120873144672231705&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;LinkedIn: &lt;a href="https://www.linkedin.com/posts/stanmobitech_bitcoin-lightning-mpesa-ugcPost-7526639549096206337-XvSh/" rel="noopener noreferrer"&gt;https://www.linkedin.com/posts/stanmobitech_bitcoin-lightning-mpesa-ugcPost-7526639549096206337-XvSh/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Facebook: &lt;a href="https://www.facebook.com/reel/2325100758235989" rel="noopener noreferrer"&gt;https://www.facebook.com/reel/2325100758235989&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Instagram Reel: &lt;a href="https://www.instagram.com/reel/DfpL66uSlP_/" rel="noopener noreferrer"&gt;https://www.instagram.com/reel/DfpL66uSlP_/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;TikTok: &lt;a href="https://www.tiktok.com/@altradits/video/7707279854151994637" rel="noopener noreferrer"&gt;https://www.tiktok.com/@altradits/video/7707279854151994637&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>bitcoin</category>
      <category>lightning</category>
      <category>opensource</category>
      <category>africa</category>
    </item>
    <item>
      <title>Shop no. 4 takes bitcoin in Kisumu. Now I need people who earn it</title>
      <dc:creator>Stanley Chege Thuita</dc:creator>
      <pubDate>Wed, 11 Nov 2026 17:37:14 +0000</pubDate>
      <link>https://dev.to/altradits/shop-no-4-takes-bitcoin-in-kisumu-now-i-need-people-who-earn-it-285j</link>
      <guid>https://dev.to/altradits/shop-no-4-takes-bitcoin-in-kisumu-now-i-need-people-who-earn-it-285j</guid>
      <description>&lt;p&gt;I set out to bring one Kisumu merchant onto bitcoin every week. We're already at four, and it has been amazing.&lt;/p&gt;

&lt;p&gt;Shop no. 4 is &lt;strong&gt;Lake Basin Mall Hotel&lt;/strong&gt;, run by Nancy. It's my favourite food spot: delicious local traditional food. My usual is fish and ugali, but if there's omena, my day is made. Today her poster went up on the wall, next to the chapati on the board.&lt;/p&gt;


&lt;div&gt;
    &lt;iframe src="https://www.youtube.com/embed/gX8zwYqfg2Q" width="315" height="560"&gt;
    &lt;/iframe&gt;
  &lt;/div&gt;


&lt;h2&gt;
  
  
  What Altradits is doing in Kisumu
&lt;/h2&gt;

&lt;p&gt;Altradits is my open-source bitcoin learning project. Its first product, &lt;strong&gt;kTown&lt;/strong&gt;, is a QR code that lets any local shop take bitcoin and receive Kenyan shillings in M-Pesa.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The customer scans the QR with any Lightning wallet and pays in sats.&lt;/li&gt;
&lt;li&gt;The shop gets shillings in M-Pesa. No new app, no exchange account, no jargon.&lt;/li&gt;
&lt;li&gt;The payment runs through my own Lightning node.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The community I'm building for is ordinary Kisumu: food vendors, small hotels, kiosks, and the people who buy from them. Most of them have only heard of bitcoin as a scam or a gamble. I want them to see it working at a till they already trust.&lt;/p&gt;

&lt;h2&gt;
  
  
  How shop no. 4 went
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;The poster is made for her shop.&lt;/strong&gt; Shop name, her own QR, "Bitcoin accepted here".&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;It's laminated&lt;/strong&gt; so it survives rain, flour and busy hands.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;I carry it across Kisumu&lt;/strong&gt; and put it up on her wall.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;I pay first.&lt;/strong&gt; I convert part of my own shillings into sats and buy something with the QR, so the merchant sees the money land in M-Pesa.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;That demo is always the moment. Every merchant is amazed, and every one asks why more people don't use this.&lt;/p&gt;

&lt;h2&gt;
  
  
  Register your shop (it's free)
&lt;/h2&gt;

&lt;p&gt;If you run a shop in Kisumu, or anywhere you have M-Pesa:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Open &lt;a href="https://altradits.com/ktown/" rel="noopener noreferrer"&gt;https://altradits.com/ktown/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Enter your M-Pesa number, shop name and the M-Pesa name as M-Pesa shows it, and set a 6-digit PIN.&lt;/li&gt;
&lt;li&gt;Your shop QR is ready. Print it, or message me and I'll bring a laminated poster.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Merchants don't pay me anything.&lt;/p&gt;

&lt;h2&gt;
  
  
  Sponsor the next shop
&lt;/h2&gt;

&lt;p&gt;Each QR poster costs me about &lt;strong&gt;$1&lt;/strong&gt; to make. I have no sponsor. I pay for it myself.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Donate in sats&lt;/strong&gt; (straight to my own node): &lt;a href="https://altradits.com/donate.html" rel="noopener noreferrer"&gt;https://altradits.com/donate.html&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Sponsor a shop onboarding:&lt;/strong&gt; $1 covers one poster. More covers my transport and the sats I spend in the demo.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Collaborate:&lt;/strong&gt; if you build on Lightning, run a bitcoin community, or employ people who could be paid in bitcoin, talk to me.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The honest part: my nightmare
&lt;/h2&gt;

&lt;p&gt;Today was hard. I'm balancing class work, learning to contribute to open-source bitcoin projects, and looking for a paying job so I can keep this dream for Kisumu alive.&lt;/p&gt;

&lt;p&gt;I'm not stopping. I'm using everything I have so merchants have what they need to take bitcoin.&lt;/p&gt;

&lt;p&gt;But one question keeps me up every night: &lt;strong&gt;where do people in Kisumu earn bitcoin?&lt;/strong&gt; A shop that accepts bitcoin needs someone who spends it. Right now that's mostly me, with sats I bought with my own shillings.&lt;/p&gt;

&lt;p&gt;So I need help on the other side too:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Remote work, bountiShop no. 4 takes bitcoin in Kisumu. Now I need people who earn ites or gigs that pay in sats&lt;/li&gt;
&lt;li&gt;Employers or projects willing to pay Kenyan contributors in bitcoin&lt;/li&gt;
&lt;li&gt;Developers and educators who want to teach people here to build and earn&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It starts with one merchant and one bitcoin spender. We have four merchants. Help me find the spenders.&lt;/p&gt;

&lt;h2&gt;
  
  
  Earlier in the journey
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Shops 1 and 2: &lt;a href="https://dev.to/altradits/a-1-qr-code-that-lets-kisumu-shops-take-bitcoin-and-get-m-pesa-35fk"&gt;https://dev.to/altradits/a-1-qr-code-that-lets-kisumu-shops-take-bitcoin-and-get-m-pesa-35fk&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;kTown: &lt;a href="https://altradits.com/ktown/" rel="noopener noreferrer"&gt;https://altradits.com/ktown/&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Watch and follow
&lt;/h2&gt;

&lt;p&gt;The video and updates are on every platform. Each one links back here for the full story.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;YouTube Short: &lt;a href="https://youtube.com/shorts/gX8zwYqfg2Q" rel="noopener noreferrer"&gt;https://youtube.com/shorts/gX8zwYqfg2Q&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;X thread: &lt;a href="https://x.com/altradits/status/2120571962887913816" rel="noopener noreferrer"&gt;https://x.com/altradits/status/2120571962887913816&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;LinkedIn: &lt;a href="https://www.linkedin.com/posts/stanmobitech_bitcoin-lightning-mpesa-ugcPost-7526338080111439872-1f8q/" rel="noopener noreferrer"&gt;https://www.linkedin.com/posts/stanmobitech_bitcoin-lightning-mpesa-ugcPost-7526338080111439872-1f8q/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Facebook: &lt;a href="https://www.facebook.com/reel/1797704094871190" rel="noopener noreferrer"&gt;https://www.facebook.com/reel/1797704094871190&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Instagram Reel: &lt;a href="https://www.instagram.com/reel/DfnDGNeMJvT/" rel="noopener noreferrer"&gt;https://www.instagram.com/reel/DfnDGNeMJvT/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;TikTok: &lt;a href="https://www.tiktok.com/@altradits/video/7706971903646338318" rel="noopener noreferrer"&gt;https://www.tiktok.com/@altradits/video/7706971903646338318&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>bitcoin</category>
      <category>lightning</category>
      <category>opensource</category>
      <category>africa</category>
    </item>
    <item>
      <title>A $1 QR code that lets Kisumu shops take bitcoin and get M-Pesa</title>
      <dc:creator>Stanley Chege Thuita</dc:creator>
      <pubDate>Mon, 09 Nov 2026 22:48:45 +0000</pubDate>
      <link>https://dev.to/altradits/a-1-qr-code-that-lets-kisumu-shops-take-bitcoin-and-get-m-pesa-35fk</link>
      <guid>https://dev.to/altradits/a-1-qr-code-that-lets-kisumu-shops-take-bitcoin-and-get-m-pesa-35fk</guid>
      <description>&lt;p&gt;On 8 November 2026 two small shops in Kisumu started accepting bitcoin.&lt;/p&gt;

&lt;p&gt;The customer scans a QR code with any Lightning wallet and pays in sats. The shop receives Kenyan shillings in M-Pesa. The shopkeeper doesn't need a wallet, an exchange account or any knowledge of bitcoin. The till works the way it always has.&lt;/p&gt;


&lt;div&gt;
    &lt;iframe src="https://www.youtube.com/embed/j7oWuEKSHOo" width="315" height="560"&gt;
    &lt;/iframe&gt;
  &lt;/div&gt;


&lt;h2&gt;
  
  
  How onboarding works
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Meet the merchant.&lt;/strong&gt; I walk the shops, explain how it works and answer questions.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Set up the QR.&lt;/strong&gt; Each shop gets its own QR code, printed on the spot.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Scan and pay in sats.&lt;/strong&gt; Any Lightning wallet works.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;It lands in M-Pesa.&lt;/strong&gt; Shillings go straight to the merchant's phone.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The product is called kTown: &lt;a href="https://altradits.com/ktown/" rel="noopener noreferrer"&gt;https://altradits.com/ktown/&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What it costs, and who pays
&lt;/h2&gt;

&lt;p&gt;Each QR code costs me about &lt;strong&gt;$1&lt;/strong&gt; to produce.&lt;/p&gt;

&lt;p&gt;The merchants don't pay me anything. I have no sponsor. I pay for it myself.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why I'm doing it
&lt;/h2&gt;

&lt;p&gt;Most people in Kisumu have only heard of bitcoin as a scam or a gamble. I want to change that story where it matters most: in the shops where people buy their bread and airtime.&lt;/p&gt;

&lt;p&gt;The next group of bitcoin advocates in Kisumu should start with shops that already accept bitcoin. There should also be local developers trained to build bitcoin tools for local businesses and the community.&lt;/p&gt;

&lt;p&gt;That future isn't here yet. Until it is, I'll keep doing whatever I can to lay the foundation for bitcoin adoption in Kisumu, one shop a week.&lt;/p&gt;

&lt;h2&gt;
  
  
  What's next
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;One new merchant every week.&lt;/li&gt;
&lt;li&gt;More time on open-source bitcoin work. I'm also preparing a Btrust application.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  How you can help
&lt;/h2&gt;

&lt;p&gt;I'm open to help, sponsorship and collaboration:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Sponsor QR codes for more shops.&lt;/strong&gt; $1 puts one shop on bitcoin.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Collaborate&lt;/strong&gt; if you're building on Lightning or work with merchants in East Africa.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Support the work:&lt;/strong&gt; &lt;a href="https://altradits.com/donate.html" rel="noopener noreferrer"&gt;https://altradits.com/donate.html&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Watch and follow
&lt;/h2&gt;

&lt;p&gt;The 40-second video and updates are on every platform. Each one links back here for the full story.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;YouTube Short: &lt;a href="https://youtube.com/shorts/j7oWuEKSHOo" rel="noopener noreferrer"&gt;https://youtube.com/shorts/j7oWuEKSHOo&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;X thread: &lt;a href="https://x.com/altradits/status/2119926618558701716" rel="noopener noreferrer"&gt;https://x.com/altradits/status/2119926618558701716&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Instagram Reel: &lt;a href="https://www.instagram.com/altradits/reel/DfidNDMByZd/" rel="noopener noreferrer"&gt;https://www.instagram.com/altradits/reel/DfidNDMByZd/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;TikTok: &lt;a href="https://www.tiktok.com/@altradits/video/7706310396126186766" rel="noopener noreferrer"&gt;https://www.tiktok.com/@altradits/video/7706310396126186766&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;LinkedIn: &lt;a href="https://www.linkedin.com/posts/stanmobitech_bitcoin-lightning-mpesa-ugcPost-7526317526901862401-ccN7/" rel="noopener noreferrer"&gt;https://www.linkedin.com/posts/stanmobitech_bitcoin-lightning-mpesa-ugcPost-7526317526901862401-ccN7/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Facebook: &lt;a href="https://www.facebook.com/reel/1150268490789490" rel="noopener noreferrer"&gt;https://www.facebook.com/reel/1150268490789490&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;kTown, the product: &lt;a href="https://altradits.com/ktown/" rel="noopener noreferrer"&gt;https://altradits.com/ktown/&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>bitcoin</category>
      <category>lightning</category>
      <category>opensource</category>
      <category>africa</category>
    </item>
    <item>
      <title>Going quiet, working in public: my road to Bitcoin review</title>
      <dc:creator>Stanley Chege Thuita</dc:creator>
      <pubDate>Sun, 08 Nov 2026 10:06:17 +0000</pubDate>
      <link>https://dev.to/altradits/going-quiet-working-in-public-my-road-to-bitcoin-review-212m</link>
      <guid>https://dev.to/altradits/going-quiet-working-in-public-my-road-to-bitcoin-review-212m</guid>
      <description>&lt;p&gt;Today I start a new chapter: going quiet, working in public, and getting very good at one thing: understanding and reviewing Bitcoin code. My tracker on altradits.com records every day from my GitHub. Nothing ticked by hand.&lt;/p&gt;

&lt;p&gt;The goal: a Btrust grant to work full time on Lightning (LND). The bar: one project, five merged code PRs, careful reviews of other people's work, a six-month plan, and two people on the project who'll vouch for me.&lt;/p&gt;

&lt;p&gt;Bitcoin has many builders and few reviewers. Reviewing means building someone's change, running it, trying to break it, and saying exactly what I tested. That's the skill I'm training every week.&lt;/p&gt;

&lt;p&gt;My Mac is my lab: a Lightning node on mainnet, regtest and signet nodes to break things safely, and drills I repeat until they're boring. Today I withdrew from my own node and recorded every step, including two failed attempts.&lt;/p&gt;

&lt;p&gt;Code is only half of it. Bitcoin has to work where I live. So far one merchant in my community has said yes: Roseline, who runs Mama Jobu Hotel at Mambo Leo Junction.&lt;/p&gt;

&lt;p&gt;Today I deliver her official Altradits QR: "We accept Bitcoin. Scan here to pay." Customers pay in sats. She receives M-Pesa.&lt;/p&gt;

&lt;p&gt;Mama Jobu is a small, makeshift hotel. My hope, Inshallah, is to see it grow: a safer building, proper storage, better food handling. If Bitcoin brings her even a few new customers, that's a start.&lt;/p&gt;

&lt;p&gt;From today: one merchant a week. I'll explain Bitcoin in plain words, set them up, and share what works and what doesn't. Week 1: Roseline ✅&lt;/p&gt;

&lt;p&gt;Follow along: &lt;a href="https://altradits.com/tracker" rel="noopener noreferrer"&gt;altradits.com/tracker&lt;/a&gt; and &lt;a href="https://github.com/altradits" rel="noopener noreferrer"&gt;github.com/altradits&lt;/a&gt;. If you're a Bitcoin developer willing to look over my reviews, I'd be grateful. ⚡&lt;/p&gt;

</description>
      <category>bitcoin</category>
      <category>lightning</category>
      <category>opensource</category>
      <category>career</category>
    </item>
    <item>
      <title>From Piscine Go to a Bitcoin node in Kisumu: what eight months of building taught me</title>
      <dc:creator>Stanley Chege Thuita</dc:creator>
      <pubDate>Sat, 07 Nov 2026 04:43:09 +0000</pubDate>
      <link>https://dev.to/altradits/from-piscine-go-to-a-bitcoin-node-in-kisumu-what-eight-months-of-building-taught-me-5b0k</link>
      <guid>https://dev.to/altradits/from-piscine-go-to-a-bitcoin-node-in-kisumu-what-eight-months-of-building-taught-me-5b0k</guid>
      <description>&lt;p&gt;In March I was writing &lt;code&gt;IsNegative&lt;/code&gt; and &lt;code&gt;PrintNbr&lt;/code&gt; in the Zone01 Kisumu Piscine. This week a Lightning node I run is paying merchants in Kisumu straight to their M-Pesa. This post is the path between those two points, written down so I can see it clearly and so anyone starting out can see that the small exercises lead somewhere.&lt;/p&gt;

&lt;h2&gt;
  
  
  March to April: the boring part that mattered most
&lt;/h2&gt;

&lt;p&gt;The Piscine was 21 days of small Go exercises: runes, slices, pointers, linked lists, binary trees. Hundreds of commits, most of them tiny. I did not see the point of &lt;code&gt;BTreeDeleteNode&lt;/code&gt; at the time. I see it now every time I read Bitcoin Core code that walks a structure and has to leave it valid.&lt;/p&gt;

&lt;p&gt;Then came the group projects: go-reloaded, ascii-art, push-swap, groupie-tracker, lem-in, forum. They taught me the things a tutorial skips. How to split work across a team, how to review a pull request without breaking someone else's branch, how to write the test before arguing about the code.&lt;/p&gt;

&lt;h2&gt;
  
  
  April to August: building things nobody asked for
&lt;/h2&gt;

&lt;p&gt;In parallel I kept starting small products of my own:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A coding platform where a learner writes Go on one side and reads the instructions on the other.&lt;/li&gt;
&lt;li&gt;BursaryHub, a full-stack bursary application.&lt;/li&gt;
&lt;li&gt;YeboBank, a savings and chama product for Kenyan groups.&lt;/li&gt;
&lt;li&gt;Convert, my first attempt at a Bitcoin to M-Pesa screen.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Most of them were not finished. All of them taught me something I used later: Docker, PostgreSQL, Next.js, payment APIs, and above all that a product is the part the user touches, not the code I am proud of.&lt;/p&gt;

&lt;h2&gt;
  
  
  September: one problem worth solving
&lt;/h2&gt;

&lt;p&gt;By September the problem was clear. In Kisumu many small shop owners have M-Pesa but no smartphone, and some cannot read. Bitcoin payments are cheap and fast, but only if the merchant can actually receive them in the money they already use.&lt;/p&gt;

&lt;p&gt;So I built Yebente, a Bitcoin and Lightning wallet with M-Pesa Daraja integration, and started studying Bitcoin Core properly: PSBTs, HTLCs, mempool policy, reading real pull requests in the Bitcoin Core repository.&lt;/p&gt;

&lt;h2&gt;
  
  
  October: the node
&lt;/h2&gt;

&lt;p&gt;In mid October I connected my own LND node and moved altradits.com onto it. Everything since then runs on that node:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;kTown&lt;/strong&gt;, a Bitcoin till. The merchant gets a QR code. A customer pays from any Lightning wallet, and the merchant receives the shilling amount on their M-Pesa phone. The merchant does not need a smartphone or a wallet.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A hosted wallet&lt;/strong&gt; with very small fees for Kisumu merchants.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Learning tools&lt;/strong&gt;: a Bitcoin Core lab, Go challenges and small games that teach how blocks and the mempool work.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I also joined the work around BitDevs Kisumu with Btrust, signed the Education Network Charter with My First Bitcoin, and submitted Altradits to the Meta Global AI Developer Hackathon on 4 November.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I would tell someone in their first Piscine week
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;The small exercises are the foundation.&lt;/strong&gt; Linked lists and runes come back when you read real systems code.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Ship something a real person can touch&lt;/strong&gt;, even if it is ugly. Feedback from one shop owner is worth more than a week of polish.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Pick one hard domain and stay in it.&lt;/strong&gt; For me that is Bitcoin. Going deep in one place made everything else easier to learn.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Write it down.&lt;/strong&gt; Commits, standups, posts like this one. Your record of the work is how others, and you, can see the progress.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  What is next
&lt;/h2&gt;

&lt;p&gt;Next is Go without shortcuts. I am working through Bitcoin and Lightning code by hand, without AI writing it for me, so that by 2027 I can contribute to Bitcoin open source and help the BitDevs Kisumu students do the same.&lt;/p&gt;

&lt;p&gt;If you are building with Bitcoin in East Africa, or you run a small shop in Kisumu and want to try kTown, find me at &lt;a href="https://altradits.com" rel="noopener noreferrer"&gt;altradits.com&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>bitcoin</category>
      <category>go</category>
      <category>lightning</category>
      <category>africa</category>
    </item>
    <item>
      <title>The Most Misunderstood 73 Lines in Go</title>
      <dc:creator>Stanley Chege Thuita</dc:creator>
      <pubDate>Tue, 09 Jun 2026 16:45:35 +0000</pubDate>
      <link>https://dev.to/altradits/the-most-misunderstood-73-lines-in-go-31p4</link>
      <guid>https://dev.to/altradits/the-most-misunderstood-73-lines-in-go-31p4</guid>
      <description>&lt;h2&gt;
  
  
  &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0fjqlaykbwjd3wey7lpk.png" alt="A software developer sits late at night at a cluttered workstation, struggling to solve a complex Go programming challenge. Multiple screens display Go code, error messages, and concurrency issues, while notes and diagrams around the desk highlight debugging efforts. The developer's stressed posture and focused expression capture the frustration and determination that often come with tackling difficult coding problems. The dim lighting and intense workspace atmosphere emphasize the pressure of finding a solution." width="800" height="640"&gt;
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;The first time I saw &lt;code&gt;context.Context&lt;/code&gt;, I thought:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;"Oh, a way to pass timeouts. Nice."&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I was wrong.&lt;/p&gt;

&lt;p&gt;Embarrassingly wrong.&lt;/p&gt;

&lt;p&gt;The kind of wrong that quietly leaks goroutines for &lt;strong&gt;18 months&lt;/strong&gt; before someone notices.&lt;/p&gt;

&lt;p&gt;Then I thought:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;"Okay, it's for cancellation."&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Still wrong.&lt;/p&gt;

&lt;p&gt;Closer.&lt;/p&gt;

&lt;p&gt;But wrong.&lt;/p&gt;

&lt;p&gt;The truth is stranger—and far more powerful.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;context.Context&lt;/code&gt; is:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The most elegant solution to a problem you didn't know you had&lt;/li&gt;
&lt;li&gt;The most common source of bugs you don't realize you're writing&lt;/li&gt;
&lt;li&gt;The backbone of modern Go concurrency&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let's fix that.&lt;/p&gt;

&lt;p&gt;Forever.&lt;/p&gt;




&lt;p&gt;Part 1: The Lie They Tell You About Context&lt;/p&gt;

&lt;p&gt;Most tutorials teach Context like this:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;"Context is a way to set deadlines and cancel operations."&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cancel&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;WithTimeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Background&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
    &lt;span class="m"&gt;5&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Second&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;defer&lt;/span&gt; &lt;span class="n"&gt;cancel&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;doSomething&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;✅ Correct&lt;/p&gt;

&lt;p&gt;✅ Useful&lt;/p&gt;

&lt;p&gt;❌ Only 5% of the story&lt;/p&gt;




&lt;h2&gt;
  
  
  The Real Definition
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Context is an immutable value that flows through your call graph, carrying cancellation signals, deadlines, and request-scoped data from root to leaf.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It never flows backward.&lt;/p&gt;

&lt;p&gt;It never flows sideways.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Read that twice.&lt;/p&gt;

&lt;p&gt;Everything else follows from this.&lt;/p&gt;




&lt;p&gt;Part 2: The One Rule That Explains Everything&lt;/p&gt;

&lt;h2&gt;
  
  
  Context flows DOWN.
&lt;/h2&gt;

&lt;p&gt;Never up.&lt;/p&gt;

&lt;p&gt;Never sideways.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Request
   │
   ▼
Handler
   │
   ▼
Service
   │
   ▼
Repository
   │
   ▼
Database
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The same context travels through the entire operation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ctx ──────────────────────────────►
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Creating Child Contexts
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;parent&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;ctx&lt;/span&gt;

&lt;span class="n"&gt;child&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cancel&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt;
    &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;WithCancel&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;parent&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;grandchild&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt;
    &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;WithTimeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;child&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Second&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Perfectly legal.&lt;/p&gt;




&lt;h2&gt;
  
  
  What You Cannot Do
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;parent&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;WithCancel&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;child&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;❌ Doesn't exist.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;merged&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Merge&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ctx1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ctx2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;❌ Also doesn't exist.&lt;/p&gt;




&lt;h2&gt;
  
  
  Why?
&lt;/h2&gt;

&lt;p&gt;Because a context represents:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;One request&lt;/li&gt;
&lt;li&gt;One operation&lt;/li&gt;
&lt;li&gt;One unit of work&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When a parent dies:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Parent
 ├── Child A
 ├── Child B
 └── Child C
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Everything below it dies too.&lt;/p&gt;

&lt;p&gt;But killing a child never affects the parent.&lt;/p&gt;

&lt;p&gt;That predictability is the entire point.&lt;/p&gt;




&lt;p&gt;Part 3: The Four Context Superpowers&lt;/p&gt;




&lt;p&gt;⚡ Superpower 1 — Cancellation&lt;/p&gt;

&lt;p&gt;The one everyone knows.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;SearchProducts&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;ctx&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Context&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;query&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;([]&lt;/span&gt;&lt;span class="n"&gt;Product&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="n"&gt;searchCtx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cancel&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt;
        &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;WithTimeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Second&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;defer&lt;/span&gt; &lt;span class="n"&gt;cancel&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Query&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;searchCtx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s"&gt;"SELECT * FROM products ..."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When the timeout expires:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Database receives cancellation&lt;/li&gt;
&lt;li&gt;Query stops&lt;/li&gt;
&lt;li&gt;Resources get cleaned up&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;No zombies.&lt;/p&gt;

&lt;p&gt;No hanging connections.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Secret Nobody Mentions
&lt;/h2&gt;

&lt;p&gt;Cancellation is &lt;strong&gt;cooperative&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Context doesn't magically stop your code.&lt;/p&gt;

&lt;p&gt;Your code must cooperate.&lt;/p&gt;

&lt;h3&gt;
  
  
  Bad
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;SlowOperation&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ctx&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Context&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="kt"&gt;error&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="m"&gt;1_000_000&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;doExpensiveThing&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;select&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt;&lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Done&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Err&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="k"&gt;default&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="no"&gt;nil&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This ignores cancellation until the end.&lt;/p&gt;




&lt;h3&gt;
  
  
  Good
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;SlowOperation&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ctx&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Context&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="kt"&gt;error&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="m"&gt;1_000_000&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

        &lt;span class="k"&gt;select&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt;&lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Done&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Err&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="k"&gt;default&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;

        &lt;span class="n"&gt;doExpensiveThing&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="no"&gt;nil&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Check often.&lt;/p&gt;

&lt;p&gt;Exit early.&lt;/p&gt;




&lt;p&gt;⚡ Superpower 2 — Value Propagation&lt;/p&gt;

&lt;p&gt;Context can carry request-scoped metadata.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;ctx&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;WithValue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;userIDKey&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s"&gt;"alice-123"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Later:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;userID&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Value&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;userIDKey&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Danger Zone
&lt;/h2&gt;

&lt;p&gt;This compiles:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;userID&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Value&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;userIDKey&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And this also compiles:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;userID&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Value&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;userIDKey&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The second one explodes at runtime.&lt;/p&gt;




&lt;h2&gt;
  
  
  Use Context Values For...
&lt;/h2&gt;

&lt;h3&gt;
  
  
  ✅ Good
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Request IDs&lt;/li&gt;
&lt;li&gt;User IDs&lt;/li&gt;
&lt;li&gt;Tenant IDs&lt;/li&gt;
&lt;li&gt;Tracing&lt;/li&gt;
&lt;li&gt;Logging metadata&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  ❌ Bad
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Database connections&lt;/li&gt;
&lt;li&gt;Service dependencies&lt;/li&gt;
&lt;li&gt;Business logic inputs&lt;/li&gt;
&lt;li&gt;Optional configuration&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Golden Rule
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;If business logic requires it, pass it explicitly.&lt;/p&gt;

&lt;p&gt;If it's plumbing, context is acceptable.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;p&gt;⚡ Superpower 3 — Deadline Propagation&lt;/p&gt;

&lt;p&gt;Parent deadlines always win.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cancel&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt;
    &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;WithTimeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Background&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
        &lt;span class="m"&gt;5&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Second&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;defer&lt;/span&gt; &lt;span class="n"&gt;cancel&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now create a child:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;childCtx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;childCancel&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt;
    &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;WithTimeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="m"&gt;10&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Second&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;defer&lt;/span&gt; &lt;span class="n"&gt;childCancel&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Guess the deadline?&lt;/p&gt;

&lt;p&gt;Not 10 seconds.&lt;/p&gt;

&lt;p&gt;Still 5.&lt;/p&gt;




&lt;h2&gt;
  
  
  Rule
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Context deadlines are minimal.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The strictest deadline wins.&lt;/p&gt;

&lt;p&gt;Always.&lt;/p&gt;

&lt;p&gt;This prevents downstream code from extending upstream limits.&lt;/p&gt;




&lt;p&gt;⚡ Superpower 4 — Goroutine Lifecycle Management&lt;/p&gt;

&lt;p&gt;This is where senior engineers separate themselves.&lt;/p&gt;




&lt;h2&gt;
  
  
  Bad
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;startWorker&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;go&lt;/span&gt; &lt;span class="k"&gt;func&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Sleep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Second&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="n"&gt;doWork&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}()&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This worker lives forever.&lt;/p&gt;

&lt;p&gt;Or until production starts smoking.&lt;/p&gt;




&lt;h2&gt;
  
  
  Good
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;startWorker&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ctx&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Context&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;go&lt;/span&gt; &lt;span class="k"&gt;func&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

        &lt;span class="n"&gt;ticker&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;NewTicker&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Second&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;defer&lt;/span&gt; &lt;span class="n"&gt;ticker&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Stop&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;select&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

            &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt;&lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Done&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
                &lt;span class="k"&gt;return&lt;/span&gt;

            &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt;&lt;span class="n"&gt;ticker&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;C&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
                &lt;span class="n"&gt;doWork&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}()&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Usage:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cancel&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt;
    &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;WithCancel&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Background&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;startWorker&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;cancel&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Worker exits gracefully.&lt;/p&gt;




&lt;h2&gt;
  
  
  Rule
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Every goroutine without a context is a potential memory leak.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Every.&lt;/p&gt;

&lt;p&gt;Single.&lt;/p&gt;

&lt;p&gt;One.&lt;/p&gt;




&lt;p&gt;Part 4: The Context Crimes&lt;/p&gt;




&lt;p&gt;☠️ Crime 1 — Storing Context in Structs&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="n"&gt;Repository&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;ctx&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Context&lt;/span&gt;
    &lt;span class="n"&gt;db&lt;/span&gt;  &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;sql&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;DB&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Never do this.&lt;/p&gt;

&lt;p&gt;Why?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Context becomes stale&lt;/li&gt;
&lt;li&gt;Request ownership becomes unclear&lt;/li&gt;
&lt;li&gt;Testing becomes painful&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Correct
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="n"&gt;Repository&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;db&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;sql&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;DB&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;Repository&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;GetUser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;ctx&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Context&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;User&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="o"&gt;...&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;☠️ Crime 2 — Ignoring Cancellation&lt;/p&gt;

&lt;p&gt;Bad:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This uses a background context.&lt;/p&gt;

&lt;p&gt;Your timeout is ignored.&lt;/p&gt;




&lt;p&gt;Good:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt;
    &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;NewRequestWithContext&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s"&gt;"GET"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="no"&gt;nil&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;resp&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt;
    &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;DefaultClient&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Do&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now cancellation actually works.&lt;/p&gt;




&lt;p&gt;☠️ Crime 3 — Background Work Using Request Context&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;go&lt;/span&gt; &lt;span class="k"&gt;func&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;expensiveOperation&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Context&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;span class="p"&gt;}()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Looks fine.&lt;/p&gt;

&lt;p&gt;It's not.&lt;/p&gt;

&lt;p&gt;Request ends.&lt;/p&gt;

&lt;p&gt;Context cancels.&lt;/p&gt;

&lt;p&gt;Background work dies.&lt;/p&gt;




&lt;h3&gt;
  
  
  Fix
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;bgCtx&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;WithoutCancel&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Context&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now it survives the request.&lt;/p&gt;




&lt;p&gt;☠️ Crime 4 — Nil Contexts&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;ctx&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="no"&gt;nil&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;ctx&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Background&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Don't.&lt;/p&gt;

&lt;p&gt;A nil context is a caller bug.&lt;/p&gt;

&lt;p&gt;Make it fail loudly.&lt;/p&gt;




&lt;p&gt;Part 5: Patterns You'll Actually Use&lt;/p&gt;




&lt;h2&gt;
  
  
  🥪 The Timeout Sandwich
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;apiCtx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cancel&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt;
    &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;WithTimeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Second&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;defer&lt;/span&gt; &lt;span class="n"&gt;cancel&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Create short-lived child contexts around external dependencies.&lt;/p&gt;

&lt;p&gt;Always.&lt;/p&gt;




&lt;h2&gt;
  
  
  🆔 Request ID Propagation
&lt;/h2&gt;

&lt;p&gt;Middleware:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;ctx&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;WithRequestID&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Context&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
    &lt;span class="n"&gt;requestID&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Handler:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;log&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="s"&gt;"[%s] Processing request"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;GetRequestID&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Instant traceability.&lt;/p&gt;




&lt;h2&gt;
  
  
  🔀 Fan-Out With Early Cancellation
&lt;/h2&gt;

&lt;p&gt;Launch multiple queries:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;search&lt;/span&gt;
&lt;span class="n"&gt;recommendation&lt;/span&gt;
&lt;span class="n"&gt;inventory&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Collect results.&lt;/p&gt;

&lt;p&gt;Exit immediately on failure.&lt;/p&gt;

&lt;p&gt;All goroutines respect the same context.&lt;/p&gt;

&lt;p&gt;One cancellation signal controls everything.&lt;/p&gt;

&lt;p&gt;Beautiful.&lt;/p&gt;




&lt;p&gt;Part 6: The Context Decision Tree&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Do you already have a context?
        │
   ┌────┴────┐
   │         │
  YES       NO
   │         │
 Pass it     ▼
 down     Background job?
               │
        ┌──────┴──────┐
        │             │
       YES           NO
        │             │
Background()      TODO()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;The Rule That Prevents Leaks&lt;/p&gt;

&lt;p&gt;Every one of these:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;WithCancel&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;...&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;WithTimeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;...&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;WithDeadline&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;...&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Must have:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;defer&lt;/span&gt; &lt;span class="n"&gt;cancel&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Immediately.&lt;/p&gt;

&lt;p&gt;Not later.&lt;/p&gt;

&lt;p&gt;Immediately.&lt;/p&gt;




&lt;p&gt;🔍 This Week's Challenge&lt;/p&gt;

&lt;p&gt;Audit your codebase.&lt;/p&gt;

&lt;p&gt;Find:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;[ ] Goroutines without contexts&lt;/li&gt;
&lt;li&gt;[ ] Context stored in structs&lt;/li&gt;
&lt;li&gt;[ ] Raw &lt;code&gt;http.Get()&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;[ ] Missing &lt;code&gt;defer cancel()&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;[ ] Loops ignoring &lt;code&gt;ctx.Done()&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You'll find bugs.&lt;/p&gt;

&lt;p&gt;Guaranteed.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Mental Model
&lt;/h2&gt;

&lt;p&gt;Remember only this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Context flows down.
Cancellation flows up.
Values are for plumbing.
Business data is explicit.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Everything else is implementation detail.&lt;/p&gt;




&lt;h2&gt;
  
  
  One-Page Cheat Sheet
&lt;/h2&gt;

&lt;h3&gt;
  
  
  ✅ Do This
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;DoWork&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;ctx&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Context&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;arg&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="kt"&gt;error&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;doSubWork&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;arg&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cancel&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt;
    &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;WithTimeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;parent&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="m"&gt;5&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Second&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;defer&lt;/span&gt; &lt;span class="n"&gt;cancel&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;handler&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;w&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ResponseWriter&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Request&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;ctx&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Context&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  ❌ Don't Do This
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="n"&gt;Worker&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;ctx&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Context&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cancel&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt;
    &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;WithTimeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;parent&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="m"&gt;5&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Second&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c"&gt;// forgot cancel()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Final Thought
&lt;/h2&gt;

&lt;p&gt;Most developers think Context is about timeouts.&lt;/p&gt;

&lt;p&gt;It's not.&lt;/p&gt;

&lt;p&gt;Timeouts are merely a feature.&lt;/p&gt;

&lt;p&gt;The real purpose of &lt;code&gt;context.Context&lt;/code&gt; is to give an entire tree of operations a shared lifecycle.&lt;/p&gt;

&lt;p&gt;Once that clicks:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Timeouts make sense&lt;/li&gt;
&lt;li&gt;Cancellation makes sense&lt;/li&gt;
&lt;li&gt;Request scoping makes sense&lt;/li&gt;
&lt;li&gt;Goroutine management makes sense&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And suddenly those mysterious 73 lines in the standard library become one of the most elegant designs in Go.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Context flows down.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Never forget it.&lt;/p&gt;

</description>
      <category>go</category>
      <category>community</category>
      <category>architecture</category>
    </item>
    <item>
      <title>What every Go developer wishes they knew before their first production outage</title>
      <dc:creator>Stanley Chege Thuita</dc:creator>
      <pubDate>Mon, 08 Jun 2026 22:46:28 +0000</pubDate>
      <link>https://dev.to/altradits/what-every-go-developer-wishes-they-knew-before-their-first-production-outage-578g</link>
      <guid>https://dev.to/altradits/what-every-go-developer-wishes-they-knew-before-their-first-production-outage-578g</guid>
      <description>&lt;h2&gt;
  
  
  The Slice Trap That Cost Me 4 Hours (And How to Never Fall Into It Again)
&lt;/h2&gt;

&lt;p&gt;You've been there. The bug that makes no sense. The data that changes when you weren't looking. The append that silently created a monster.&lt;/p&gt;

&lt;p&gt;Let me tell you about a Tuesday night that still haunts me.&lt;/p&gt;

&lt;p&gt;The API was returning duplicate items. Not always. Just sometimes. Just when the payload was over a certain size. Just when the moon was in the seventh house.&lt;/p&gt;

&lt;p&gt;Four hours. Four developers. One slack thread with 47 messages.&lt;/p&gt;

&lt;p&gt;The culprit? A slice. Just a slice. Innocent-looking. Cute, even. And completely misunderstood by all four of us.&lt;/p&gt;

&lt;p&gt;Today, you learn what we learned. And you never make these mistakes again.&lt;/p&gt;

&lt;h2&gt;
  
  
  Part 1: The Slice Lie They Tell You
&lt;/h2&gt;

&lt;p&gt;Most tutorials teach slices like this:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"A slice is a dynamically-sized array."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This is not wrong, but it's like saying "a car is a metal box with wheels." Technically true. Completely useless when the engine fails.&lt;/p&gt;

&lt;p&gt;Here's what a slice actually is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="c"&gt;// This is NOT a slice&lt;/span&gt;
&lt;span class="n"&gt;numbers&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;// This is a slice:&lt;/span&gt;
&lt;span class="c"&gt;// A tiny struct containing:&lt;/span&gt;
&lt;span class="c"&gt;// - A pointer to an underlying array&lt;/span&gt;
&lt;span class="c"&gt;// - A length (len)&lt;/span&gt;
&lt;span class="c"&gt;// - A capacity (cap)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Visualize it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;slice := []int{1, 2, 3}

┌─────────────────────────────────────┐
│  slice (24 bytes on 64-bit arch)    │
│  ┌──────────┬──────────┬──────────┐ │
│  │  ptr ────┼─▶ [1][2][3]          │ │
│  │  len = 3 │          ↑            │ │
│  │  cap = 3 │    underlying array   │ │
│  └──────────┴──────────┴──────────┘ │
└─────────────────────────────────────┘
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The pointer is the dangerous part. Because when you copy a slice, you copy the pointer. Not the data.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;original&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="n"&gt;copycat&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;original&lt;/span&gt;  &lt;span class="c"&gt;// This copies the struct (ptr, len, cap)&lt;/span&gt;

&lt;span class="n"&gt;copycat&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;99&lt;/span&gt;

&lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;original&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;  &lt;span class="c"&gt;// 99 !!! The original changed!&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Both variables point to the same underlying array. This is intentional. This is powerful. This is also the source of 90% of slice bugs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Part 2: The 4 Slice Traps That Will Bite You
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Trap #1: The Append That Betrayed You
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;original&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="n"&gt;addElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;original&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;original&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c"&gt;// Still [1 2 3] ??? Where did 4 go?&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;addElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;4&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c"&gt;// This doesn't modify the original!&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Why this fails:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;append&lt;/code&gt; returns a new slice header. It might point to the same underlying array (if capacity allows) or a completely new array (if capacity is exceeded). But the &lt;code&gt;s&lt;/code&gt; inside the function is a copy of the header. Modifying it doesn't affect the caller's variable.&lt;/p&gt;

&lt;p&gt;The fix:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;addElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nb"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;4&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;// Or use a pointer&lt;/span&gt;
&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;addElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;4&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;The Rule:&lt;/strong&gt; If a function modifies a slice (length, capacity, or elements), either return the new slice or use a pointer.&lt;/p&gt;

&lt;h3&gt;
  
  
  Trap #2: The Shared Array That Ate My Weekend
&lt;/h3&gt;

&lt;p&gt;This is the production killer.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;users&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="n"&gt;User&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;Name&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Alice"&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;Name&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Bob"&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;Name&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Charlie"&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="c"&gt;// Store references to "admin" users&lt;/span&gt;
    &lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;admins&lt;/span&gt; &lt;span class="p"&gt;[][]&lt;/span&gt;&lt;span class="n"&gt;User&lt;/span&gt;

    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;subset&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;  &lt;span class="c"&gt;// Take a subset&lt;/span&gt;
        &lt;span class="n"&gt;admins&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;admins&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;subset&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="c"&gt;// Later... modify a user&lt;/span&gt;
    &lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"ROBERT"&lt;/span&gt;

    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;admins&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c"&gt;// "ROBERT" ??? Wait, what?&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What happened:&lt;/p&gt;

&lt;p&gt;Every &lt;code&gt;subset&lt;/code&gt; shared the same underlying array as &lt;code&gt;users&lt;/code&gt;. When you changed &lt;code&gt;users[1]&lt;/code&gt;, every slice that included that index changed too.&lt;/p&gt;

&lt;p&gt;The fix: Force a copy when you need independence.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;subset&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nb"&gt;make&lt;/span&gt;&lt;span class="p"&gt;([]&lt;/span&gt;&lt;span class="n"&gt;User&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nb"&gt;copy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;subset&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;span class="n"&gt;admins&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;admins&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;subset&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;The Rule:&lt;/strong&gt; If you need independence, copy. If you want sharing (for performance), keep the reference. But know which one you have.&lt;/p&gt;

&lt;h3&gt;
  
  
  Trap #3: The Capacity Confusion
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;s1&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nb"&gt;make&lt;/span&gt;&lt;span class="p"&gt;([]&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c"&gt;// len=3, cap=3&lt;/span&gt;
    &lt;span class="n"&gt;s2&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nb"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;4&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;      &lt;span class="c"&gt;// len=4, cap=6 (new array!)&lt;/span&gt;

    &lt;span class="n"&gt;s1&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;99&lt;/span&gt;

    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s2&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;  &lt;span class="c"&gt;// Still 0, not 99. Different arrays now.&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Append creates a new array when capacity is exceeded. Your slices diverge silently.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Rule:&lt;/strong&gt; After any append, treat the result as potentially different from the original. Never assume they share memory.&lt;/p&gt;

&lt;h3&gt;
  
  
  Trap #4: The Loop Variable Reuse (Classic)
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;users&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s"&gt;"Alice"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Bob"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Charlie"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;pointers&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;

    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="k"&gt;range&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;pointers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pointers&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c"&gt;// Same &amp;amp;name every time!&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="k"&gt;range&lt;/span&gt; &lt;span class="n"&gt;pointers&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c"&gt;// Charlie Charlie Charlie&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The horror: The loop variable &lt;code&gt;name&lt;/code&gt; is reused. Its address never changes. Every pointer points to the same memory location, which ends up holding the last value.&lt;/p&gt;

&lt;p&gt;The fix:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="k"&gt;range&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;  &lt;span class="c"&gt;// Create a new variable&lt;/span&gt;
    &lt;span class="n"&gt;pointers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pointers&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or use index:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="k"&gt;range&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;pointers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pointers&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Part 3: The Mental Model That Fixes Everything
&lt;/h2&gt;

&lt;p&gt;Stop thinking of slices as "dynamic arrays." Think of them as window views.&lt;/p&gt;

&lt;p&gt;Imagine your underlying array is a long street of houses:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[H0][H1][H2][H3][H4][H5][H6][H7]  ← Underlying array
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A slice is a window that looks at a contiguous section:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;slice1 := array[2:5]  → window looking at [H2][H3][H4]
slice2 := array[3:6]  → window looking at [H3][H4][H5]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Key insights from this model:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Two windows can look at the same house. Change H3, both windows see it.&lt;/li&gt;
&lt;li&gt;Extending a window (appending) might require moving to a new street if the current street has no more houses to the right.&lt;/li&gt;
&lt;li&gt;Copying a window doesn't copy the houses. Just the view.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Once you see slices as windows, every behavior makes sense.&lt;/p&gt;

&lt;h2&gt;
  
  
  Part 4: The Cheat Sheet You'll Actually Use
&lt;/h2&gt;

&lt;h3&gt;
  
  
  When to Copy
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Scenario&lt;/th&gt;
&lt;th&gt;Copy?&lt;/th&gt;
&lt;th&gt;Why&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Returning a slice from a function that modifies it&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;Caller expects independence&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Storing a slice for later use when original might change&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;Prevent accidental sharing&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Filtering data that will be modified later&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;Clean separation&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Performance-critical code where copying is expensive&lt;/td&gt;
&lt;td&gt;❌&lt;/td&gt;
&lt;td&gt;But document the sharing!&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  The Copy Pattern
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="c"&gt;// The safe way to copy a slice&lt;/span&gt;
&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;copySlice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;original&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nb"&gt;make&lt;/span&gt;&lt;span class="p"&gt;([]&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;original&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
    &lt;span class="nb"&gt;copy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;original&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;// Or for one line:&lt;/span&gt;
&lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nb"&gt;append&lt;/span&gt;&lt;span class="p"&gt;([]&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;nil&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;original&lt;/span&gt;&lt;span class="o"&gt;...&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  The Append Pattern (Always Use This)
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="c"&gt;// BAD: Assuming append modifies in place&lt;/span&gt;
&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c"&gt;// Caller won't see this&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;// GOOD: Return the new slice&lt;/span&gt;
&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nb"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;// GOOD: Use pointer&lt;/span&gt;
&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;// BEST: Explicit naming&lt;/span&gt;
&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;appendInt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nb"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Part 5: Real-World Examples From Production
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Example 1: The Pagination Bug
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="c"&gt;// Before: The bug&lt;/span&gt;
&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;paginate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;items&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="n"&gt;Item&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;page&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;size&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="n"&gt;Item&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;start&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;page&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;size&lt;/span&gt;
    &lt;span class="n"&gt;end&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;start&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;size&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;start&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;items&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="n"&gt;Item&lt;/span&gt;&lt;span class="p"&gt;{}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;end&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;items&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;end&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;items&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="c"&gt;// DANGER: This shares the underlying array&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;items&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;start&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="n"&gt;end&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;// Later code modifies the paginated results...&lt;/span&gt;
&lt;span class="c"&gt;// And the original changes!&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="c"&gt;// After: The fix&lt;/span&gt;
&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;paginate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;items&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="n"&gt;Item&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;page&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;size&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="n"&gt;Item&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;start&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;page&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;size&lt;/span&gt;
    &lt;span class="n"&gt;end&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;start&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;size&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;start&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;items&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="n"&gt;Item&lt;/span&gt;&lt;span class="p"&gt;{}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;end&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;items&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;end&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;items&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="c"&gt;// Safe: Create independent copy&lt;/span&gt;
    &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nb"&gt;make&lt;/span&gt;&lt;span class="p"&gt;([]&lt;/span&gt;&lt;span class="n"&gt;Item&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;end&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;start&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nb"&gt;copy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;items&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;start&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="n"&gt;end&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Example 2: The Batch Processor
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="n"&gt;Batch&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;Items&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="n"&gt;Item&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;Batch&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;Process&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c"&gt;// DANGER: This batch owns the slice&lt;/span&gt;
    &lt;span class="c"&gt;// But Process is about to modify it&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="k"&gt;range&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Items&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Items&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Processed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;true&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;Batch&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;Clone&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;Batch&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c"&gt;// Safe copy for concurrent processing&lt;/span&gt;
    &lt;span class="n"&gt;newItems&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nb"&gt;make&lt;/span&gt;&lt;span class="p"&gt;([]&lt;/span&gt;&lt;span class="n"&gt;Item&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Items&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
    &lt;span class="nb"&gt;copy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;newItems&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Items&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;Batch&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;Items&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;newItems&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Part 6: The Expert-Level Slice Optimization
&lt;/h2&gt;

&lt;p&gt;When you're ready to go deep, understand capacity planning.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="c"&gt;// Bad: Multiple reallocations&lt;/span&gt;
&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;collect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;results&lt;/span&gt; &lt;span class="k"&gt;chan&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;collected&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;  &lt;span class="c"&gt;// cap=0&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;val&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="k"&gt;range&lt;/span&gt; &lt;span class="n"&gt;results&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;collected&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;collected&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;val&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c"&gt;// Might reallocate many times&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;collected&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;// Good: Preallocate capacity (if you know or can guess)&lt;/span&gt;
&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;collect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;results&lt;/span&gt; &lt;span class="k"&gt;chan&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;collected&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nb"&gt;make&lt;/span&gt;&lt;span class="p"&gt;([]&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;100&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c"&gt;// cap=100&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;val&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="k"&gt;range&lt;/span&gt; &lt;span class="n"&gt;results&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;collected&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;collected&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;val&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c"&gt;// No allocations until &amp;gt;100&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;collected&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;// Expert: Geometric growth&lt;/span&gt;
&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;collect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;results&lt;/span&gt; &lt;span class="k"&gt;chan&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;collected&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;val&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="k"&gt;range&lt;/span&gt; &lt;span class="n"&gt;results&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;collected&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;collected&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;val&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nb"&gt;cap&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;collected&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;collected&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;collected&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="c"&gt;// At capacity, pre-allocate next size&lt;/span&gt;
            &lt;span class="n"&gt;newCap&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nb"&gt;cap&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;collected&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;
            &lt;span class="n"&gt;newSlice&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nb"&gt;make&lt;/span&gt;&lt;span class="p"&gt;([]&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;collected&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;newCap&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="nb"&gt;copy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;newSlice&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;collected&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="n"&gt;collected&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;newSlice&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;collected&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But Go already does geometric growth (typically doubling up to 1024, then ~1.25x after). So honestly? Just use &lt;code&gt;append&lt;/code&gt; and trust it, unless you've measured a performance problem.&lt;/p&gt;

&lt;h2&gt;
  
  
  This Week's Challenge
&lt;/h2&gt;

&lt;p&gt;Find every slice in your current Go code. For each one, ask:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Who owns the underlying array? (Who can modify it?)&lt;/li&gt;
&lt;li&gt;Is this slice shared? (Passed to functions? Stored in structs?)&lt;/li&gt;
&lt;li&gt;Could an append cause unexpected behavior? (Is the result assigned back?)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If you can't answer these for any slice, you have a potential bug. Fix it now.&lt;/p&gt;

&lt;h2&gt;
  
  
  Next Week Preview
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;"Context: The Most Misunderstood 73 Lines in Go"&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We'll dissect Go's &lt;code&gt;context&lt;/code&gt; package — why it's not just for timeouts, how to use it correctly, and the one pattern that causes nil pointer panics in production.&lt;/p&gt;

&lt;p&gt;Until then, remember: A slice is a window, not a closet. Looking through the same window, you see the same things.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Readers Learned Last Week
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;"I've been writing Go for 3 years and never consciously thought about 'ownership.' This changed how I design everything." — Miguel, Platform Engineer&lt;/p&gt;

&lt;p&gt;"The ownership/flow mental model made channels finally click for me." — Priya, Backend Developer&lt;/p&gt;

&lt;p&gt;"I found 3 slice bugs in my codebase after reading this. THREE." — Thomas, Tech Lead&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Share this with a Go developer who has ever said "but it worked on my machine" after a slice bug.&lt;/p&gt;

&lt;p&gt;Your Go Gazette will be in your inbox next Friday. Same Go time. Same Go channel.&lt;/p&gt;

&lt;h2&gt;
  
  
  Appendix: Slice Debugging Quick Reference
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Common Slice Mistakes and Fixes
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="c"&gt;// MISTAKE 1: Forgetting append returns new slice&lt;/span&gt;
&lt;span class="n"&gt;mySlice&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nb"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;mySlice&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;4&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c"&gt;// ❌ result discarded&lt;/span&gt;
&lt;span class="c"&gt;// Fix:&lt;/span&gt;
&lt;span class="n"&gt;mySlice&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;mySlice&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;4&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c"&gt;// ✅&lt;/span&gt;

&lt;span class="c"&gt;// MISTAKE 2: Sharing slices unintentionally&lt;/span&gt;
&lt;span class="n"&gt;sliceA&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="n"&gt;sliceB&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;sliceA&lt;/span&gt;
&lt;span class="n"&gt;sliceB&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;99&lt;/span&gt;
&lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sliceA&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;  &lt;span class="c"&gt;// 99 (unexpected)&lt;/span&gt;
&lt;span class="c"&gt;// Fix: Explicit copy&lt;/span&gt;
&lt;span class="n"&gt;sliceB&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nb"&gt;make&lt;/span&gt;&lt;span class="p"&gt;([]&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sliceA&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="nb"&gt;copy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sliceB&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sliceA&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c"&gt;// MISTAKE 3: Taking address of loop variable&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="k"&gt;range&lt;/span&gt; &lt;span class="n"&gt;slice&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;go&lt;/span&gt; &lt;span class="k"&gt;func&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c"&gt;// ❌ v is reused&lt;/span&gt;
    &lt;span class="p"&gt;}()&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="c"&gt;// Fix:&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="k"&gt;range&lt;/span&gt; &lt;span class="n"&gt;slice&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;v&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt;  &lt;span class="c"&gt;// Shadow with new variable&lt;/span&gt;
    &lt;span class="k"&gt;go&lt;/span&gt; &lt;span class="k"&gt;func&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c"&gt;// ✅&lt;/span&gt;
    &lt;span class="p"&gt;}()&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;// MISTAKE 4: Assuming capacity is sufficient&lt;/span&gt;
&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;grow&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;999&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c"&gt;// Might allocate new array&lt;/span&gt;
    &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;888&lt;/span&gt;  &lt;span class="c"&gt;// Might be lost if caller doesn't use return&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="c"&gt;// Fix: Return the slice&lt;/span&gt;
&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;grow&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;999&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;888&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Slice Capacity Growth (Go 1.18+)
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Initial Cap&lt;/th&gt;
&lt;th&gt;Append Until&lt;/th&gt;
&lt;th&gt;New Cap&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;td&gt;8&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;8&lt;/td&gt;
&lt;td&gt;9&lt;/td&gt;
&lt;td&gt;16&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;16&lt;/td&gt;
&lt;td&gt;17&lt;/td&gt;
&lt;td&gt;32&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;32&lt;/td&gt;
&lt;td&gt;33&lt;/td&gt;
&lt;td&gt;64&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;64&lt;/td&gt;
&lt;td&gt;65&lt;/td&gt;
&lt;td&gt;128&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;128&lt;/td&gt;
&lt;td&gt;129&lt;/td&gt;
&lt;td&gt;256&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;256&lt;/td&gt;
&lt;td&gt;257&lt;/td&gt;
&lt;td&gt;512&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;512&lt;/td&gt;
&lt;td&gt;513&lt;/td&gt;
&lt;td&gt;1024&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1024&lt;/td&gt;
&lt;td&gt;1025&lt;/td&gt;
&lt;td&gt;1280 (~1.25x)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;This growth pattern is a compiler implementation detail. Don't rely on it exactly, but understand it exists.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Written while debugging a slice bug at 11pm. Edited twice. Tested on Go 1.22. No AI generated the panic examples — I earned every one of them.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>go</category>
      <category>beginners</category>
      <category>developer</category>
      <category>ai</category>
    </item>
    <item>
      <title>The Mental Model That Unlocks All of Go</title>
      <dc:creator>Stanley Chege Thuita</dc:creator>
      <pubDate>Fri, 05 Jun 2026 15:01:14 +0000</pubDate>
      <link>https://dev.to/altradits/the-mental-model-that-unlocks-all-of-go-lao</link>
      <guid>https://dev.to/altradits/the-mental-model-that-unlocks-all-of-go-lao</guid>
      <description>&lt;p&gt;You want to learn Go? Really learn it, not just copy-paste from Stack Overflow?&lt;/p&gt;

&lt;p&gt;Forget syntax. Forget keywords. Forget the "right way" to format errors.&lt;/p&gt;

&lt;p&gt;There's one mental model that, once internalized, makes everything else click. Every Go feature you've struggled with — goroutines, channels, interfaces, error handling — becomes obvious.&lt;/p&gt;

&lt;p&gt;Ready?&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Go is about ownership and flow.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That's it. Two words.&lt;/p&gt;

&lt;p&gt;Let me show you why this changes everything.&lt;/p&gt;




&lt;h2&gt;
  
  
  Table of Contents
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;The Problem With Learning Go Like Other Languages&lt;/li&gt;
&lt;li&gt;The Mental Model: Ownership&lt;/li&gt;
&lt;li&gt;The Mental Model: Flow&lt;/li&gt;
&lt;li&gt;Why This Mental Model Fixes Your Toughest Go Problems&lt;/li&gt;
&lt;li&gt;The Flow Diagram You'll Draw in Your Head Forever&lt;/li&gt;
&lt;li&gt;This Week's Challenge&lt;/li&gt;
&lt;li&gt;Next Week Preview&lt;/li&gt;
&lt;li&gt;Your Homework&lt;/li&gt;
&lt;li&gt;What Other Go Developers Learned&lt;/li&gt;
&lt;li&gt;Appendix: Quick Reference Card&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;a id="problem"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The Problem With Learning Go Like Other Languages
&lt;/h2&gt;

&lt;p&gt;If you came from Python, Java, or JavaScript, you learned to think in terms of:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Objects and methods&lt;/li&gt;
&lt;li&gt;Inheritance hierarchies&lt;/li&gt;
&lt;li&gt;Shared mutable state&lt;/li&gt;
&lt;li&gt;Exceptions flying up the call stack&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Go has none of these. So you keep fighting the language.&lt;/p&gt;

&lt;p&gt;You write a loop and accidentally copy a huge struct.&lt;/p&gt;

&lt;p&gt;You spawn a goroutine and it silently panics.&lt;/p&gt;

&lt;p&gt;You try to share a map between goroutines and the program crashes randomly.&lt;/p&gt;

&lt;p&gt;You reach for a try-catch that doesn't exist.&lt;/p&gt;

&lt;p&gt;You're not bad at Go.&lt;/p&gt;

&lt;p&gt;You're using the wrong mental model.&lt;/p&gt;




&lt;p&gt;&lt;a id="ownership"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The Mental Model: Ownership
&lt;/h2&gt;

&lt;p&gt;In Go, every value has exactly one "owner" at any given time.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="n"&gt;User&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;Name&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;
    &lt;span class="n"&gt;Age&lt;/span&gt;  &lt;span class="kt"&gt;int&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;user&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;User&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;Name&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Alice"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Age&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="m"&gt;30&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="n"&gt;sendToAPI&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c"&gt;// Still "Alice"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This seems obvious.&lt;/p&gt;

&lt;p&gt;But watch what happens when you forget it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="n"&gt;BigStruct&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;Data&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="m"&gt;1024&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;process&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="n"&gt;BigStruct&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c"&gt;// Receives a full copy&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If called a million times:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;8KB × 1,000,000 = 8GB copied
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Rule #1
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Values are copied unless you explicitly share them.&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;process&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;BigStruct&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Data&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;42&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now only a pointer is copied.&lt;/p&gt;

&lt;p&gt;This explains:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Why &lt;code&gt;for range&lt;/code&gt; copies elements&lt;/li&gt;
&lt;li&gt;Why pointers are needed to modify structs&lt;/li&gt;
&lt;li&gt;Why large structs should often be passed by pointer&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;a id="flow"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The Mental Model: Flow
&lt;/h2&gt;

&lt;p&gt;In Go, data doesn't jump around randomly.&lt;/p&gt;

&lt;p&gt;It flows in predictable directions.&lt;/p&gt;

&lt;h2&gt;
  
  
  Function Calls
&lt;/h2&gt;

&lt;p&gt;Data flows &lt;strong&gt;IN&lt;/strong&gt; through arguments and &lt;strong&gt;OUT&lt;/strong&gt; through returns.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;double&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Channels
&lt;/h2&gt;

&lt;p&gt;Data flows from sender to receiver.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;ch&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nb"&gt;make&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;chan&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;go&lt;/span&gt; &lt;span class="k"&gt;func&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;ch&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt; &lt;span class="m"&gt;42&lt;/span&gt;
&lt;span class="p"&gt;}()&lt;/span&gt;

&lt;span class="n"&gt;value&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt;&lt;span class="n"&gt;ch&lt;/span&gt;

&lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Interfaces
&lt;/h2&gt;

&lt;p&gt;Behavior flows from concrete type to abstraction.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="n"&gt;Writer&lt;/span&gt; &lt;span class="k"&gt;interface&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;Write&lt;/span&gt;&lt;span class="p"&gt;([]&lt;/span&gt;&lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;w&lt;/span&gt; &lt;span class="n"&gt;Writer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Stdout&lt;/span&gt;

&lt;span class="n"&gt;w&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Write&lt;/span&gt;&lt;span class="p"&gt;([]&lt;/span&gt;&lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"hello"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Key Insight
&lt;/h3&gt;

&lt;p&gt;Go makes data flow explicit.&lt;/p&gt;

&lt;p&gt;No magical inheritance.&lt;/p&gt;

&lt;p&gt;No hidden context.&lt;/p&gt;

&lt;p&gt;No invisible control flow.&lt;/p&gt;

&lt;p&gt;You can always see:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Where data comes from&lt;/li&gt;
&lt;li&gt;Where data goes&lt;/li&gt;
&lt;li&gt;Who owns it&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;a id="problems"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Why This Mental Model Fixes Your Toughest Go Problems
&lt;/h2&gt;

&lt;h2&gt;
  
  
  Problem 1: "My goroutine panicked and my program crashed"
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Old Thinking
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Exceptions should bubble up and be caught.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Go Thinking
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Panic flows out of the goroutine and nobody receives it.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Fix
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;safeGoroutine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fn&lt;/span&gt; &lt;span class="k"&gt;func&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;go&lt;/span&gt; &lt;span class="k"&gt;func&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;defer&lt;/span&gt; &lt;span class="k"&gt;func&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nb"&gt;recover&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="no"&gt;nil&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="n"&gt;log&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Panic captured: %v"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;}()&lt;/span&gt;

        &lt;span class="n"&gt;fn&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;}()&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Problem 2: "My map panics when accessed from multiple goroutines"
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Old Thinking
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Maps should be thread-safe.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Go Thinking
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;A map should have a single owner.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Fix
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="n"&gt;mapOp&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;key&lt;/span&gt;   &lt;span class="kt"&gt;string&lt;/span&gt;
    &lt;span class="n"&gt;value&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;
    &lt;span class="n"&gt;resp&lt;/span&gt;  &lt;span class="k"&gt;chan&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;mapOwner&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ops&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt;&lt;span class="k"&gt;chan&lt;/span&gt; &lt;span class="n"&gt;mapOp&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;m&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nb"&gt;make&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;map&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;op&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="k"&gt;range&lt;/span&gt; &lt;span class="n"&gt;ops&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;op&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;op&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;
        &lt;span class="n"&gt;op&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;resp&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;op&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Ownership flows through channels.&lt;/p&gt;




&lt;h2&gt;
  
  
  Problem 3: "I'm copying huge structs everywhere and it's slow"
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Old Thinking
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;The compiler should optimize this.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Go Thinking
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Ownership is explicit. If you don't want a copy, don't make one.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Before
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="n"&gt;BigStruct&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;Process&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  After
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;BigStruct&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;Process&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Even Better
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="n"&gt;BigStruct&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;Data&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Slices already behave like lightweight references.&lt;/p&gt;




&lt;p&gt;&lt;a id="diagram"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The Flow Diagram You'll Draw in Your Head Forever
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;┌─────────────────────────────────────────────────────────┐
│                         MAIN                            │
│                                                         │
│  data ──→ func(data) ──→ result                         │
│                         │                               │
│                         │ go func()                     │
│                         ↓                               │
│                                                         │
│  ch ←── data ──→ process() ──→ ch ──→ main             │
│                                                         │
└─────────────────────────────────────────────────────────┘
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Data starts somewhere.&lt;/p&gt;

&lt;p&gt;Moves somewhere else.&lt;/p&gt;

&lt;p&gt;And optionally comes back.&lt;/p&gt;

&lt;p&gt;Whenever you're confused, ask:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Where does this data come from?&lt;/li&gt;
&lt;li&gt;Where is it going?&lt;/li&gt;
&lt;li&gt;Who owns it right now?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Answer those three questions and most Go code becomes obvious.&lt;/p&gt;




&lt;p&gt;&lt;a id="challenge"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  This Week's Challenge
&lt;/h2&gt;

&lt;p&gt;Take a Go program you've already written.&lt;/p&gt;

&lt;p&gt;Spend 15 minutes tracing:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Ownership of every variable&lt;/li&gt;
&lt;li&gt;Data flow between functions&lt;/li&gt;
&lt;li&gt;Every value copy&lt;/li&gt;
&lt;li&gt;Every shared pointer&lt;/li&gt;
&lt;li&gt;Every channel send and receive&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You'll almost certainly find:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;An unnecessary copy&lt;/li&gt;
&lt;li&gt;A hidden race condition&lt;/li&gt;
&lt;li&gt;A confusing ownership boundary&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;a id="preview"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Next Week Preview
&lt;/h2&gt;

&lt;h2&gt;
  
  
  The Slice Trap That Cost Me 4 Hours
&lt;/h2&gt;

&lt;p&gt;We'll dissect the most misunderstood data structure in Go.&lt;/p&gt;

&lt;p&gt;Topics include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Slice headers&lt;/li&gt;
&lt;li&gt;Capacity growth&lt;/li&gt;
&lt;li&gt;Hidden allocations&lt;/li&gt;
&lt;li&gt;Sub-slice memory leaks&lt;/li&gt;
&lt;li&gt;Why append() sometimes changes everything&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;a id="homework"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Your Homework
&lt;/h2&gt;

&lt;p&gt;Reply with:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;One Go concept that still confuses you&lt;/li&gt;
&lt;li&gt;One ownership/flow diagram you drew this week&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The best questions may be featured in a future article.&lt;/p&gt;




&lt;p&gt;&lt;a id="testimonials"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What Other Go Developers Learned From This Article
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;"I've been writing Go for 2 years and never thought about ownership explicitly. This reframed everything."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;— Sarah, Senior Backend Engineer&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"The panic flow explanation just saved my weekend."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;— Marcus, Startup Founder&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"Coming from Rust, I kept fighting Go. Now I see Go's version of ownership is just different."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;— David, Systems Programmer&lt;/p&gt;

&lt;p&gt;Share this article with another Go developer who might benefit from it.&lt;/p&gt;




&lt;p&gt;&lt;a id="appendix"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Appendix: Quick Reference Card
&lt;/h2&gt;

&lt;h2&gt;
  
  
  Ownership Rules
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;If you want to...&lt;/th&gt;
&lt;th&gt;Do this...&lt;/th&gt;
&lt;th&gt;Because...&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Modify a struct in a function&lt;/td&gt;
&lt;td&gt;Pass &lt;code&gt;*User&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;Otherwise you modify a copy&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Share data between goroutines&lt;/td&gt;
&lt;td&gt;Use channels or mutexes&lt;/td&gt;
&lt;td&gt;Values should have one owner&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Avoid copying large data&lt;/td&gt;
&lt;td&gt;Use slices or pointers&lt;/td&gt;
&lt;td&gt;Copies can be expensive&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Keep original unchanged&lt;/td&gt;
&lt;td&gt;Pass by value&lt;/td&gt;
&lt;td&gt;Function receives an independent copy&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  Flow Rules
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Pattern&lt;/th&gt;
&lt;th&gt;Data Flow Direction&lt;/th&gt;
&lt;th&gt;Example&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Function call&lt;/td&gt;
&lt;td&gt;IN → OUT&lt;/td&gt;
&lt;td&gt;&lt;code&gt;result := compute(input)&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Channel send&lt;/td&gt;
&lt;td&gt;INTO channel&lt;/td&gt;
&lt;td&gt;&lt;code&gt;ch &amp;lt;- value&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Channel receive&lt;/td&gt;
&lt;td&gt;OUT of channel&lt;/td&gt;
&lt;td&gt;&lt;code&gt;value := &amp;lt;-ch&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Defer&lt;/td&gt;
&lt;td&gt;To end of function&lt;/td&gt;
&lt;td&gt;&lt;code&gt;defer cleanup()&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Panic&lt;/td&gt;
&lt;td&gt;Upward until recover&lt;/td&gt;
&lt;td&gt;&lt;code&gt;recover()&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  Final Thought
&lt;/h2&gt;

&lt;p&gt;Ownership and flow.&lt;/p&gt;

&lt;p&gt;Everything else in Go is syntax.&lt;/p&gt;

&lt;p&gt;Master those two ideas and:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Goroutines make sense&lt;/li&gt;
&lt;li&gt;Channels make sense&lt;/li&gt;
&lt;li&gt;Interfaces make sense&lt;/li&gt;
&lt;li&gt;Error handling makes sense&lt;/li&gt;
&lt;li&gt;Performance tuning makes sense&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The language stops feeling strange.&lt;/p&gt;

&lt;p&gt;And starts feeling inevitable.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Written in a coffee shop at 7am. Edited twice. Tested in the Go playground three times. Every panic was real. Every fix was hard-won.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>go</category>
      <category>algorithms</category>
      <category>devops</category>
      <category>backend</category>
    </item>
  </channel>
</rss>
