<?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>Forem: Rahul</title>
    <description>The latest articles on Forem by Rahul (@rahul_t).</description>
    <link>https://forem.com/rahul_t</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.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3836084%2F13728b1b-d5a0-4cac-be4a-4bd0ee16f666.jpeg</url>
      <title>Forem: Rahul</title>
      <link>https://forem.com/rahul_t</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/rahul_t"/>
    <language>en</language>
    <item>
      <title>Beginner’s Guide to Writing AI Prompts That Work</title>
      <dc:creator>Rahul</dc:creator>
      <pubDate>Wed, 25 Mar 2026 13:13:25 +0000</pubDate>
      <link>https://forem.com/rahul_t/how-to-write-ai-prompts-that-actually-work-1b86</link>
      <guid>https://forem.com/rahul_t/how-to-write-ai-prompts-that-actually-work-1b86</guid>
      <description>&lt;h2&gt;
  
  
  🧠 Stop Asking AI Bad Questions: The Prompting Playbook That Doubles Your Results
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;Most people use AI like a search engine. The ones getting extraordinary results treat it like a brilliant colleague — and they brief it accordingly.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.unsplash.com%2Fphoto-1677442135703-1787eea5ce01%3Fw%3D1200%26auto%3Dformat%26fit%3Dcrop%26q%3D80" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.unsplash.com%2Fphoto-1677442135703-1787eea5ce01%3Fw%3D1200%26auto%3Dformat%26fit%3Dcrop%26q%3D80" alt="A person typing at a laptop with a glowing AI interface on screen" width="1200" height="675"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Reading time: ~7 minutes | Audience: Anyone who uses AI regularly&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;You've used AI. You've probably been underwhelmed at least once. You typed something reasonable, got something generic back, and quietly assumed the technology just wasn't there yet.&lt;/p&gt;

&lt;p&gt;Here's the uncomfortable truth: &lt;strong&gt;the technology was there. The prompt wasn't.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The gap between a mediocre AI output and one that genuinely impresses isn't the model — it's almost always the brief. This guide gives you the exact framework used by the people consistently getting remarkable results, plus deep playbooks for the three most common domains where AI gets used every single day.&lt;/p&gt;




&lt;h2&gt;
  
  
  Part 1 — The Anatomy of a Great Prompt
&lt;/h2&gt;

&lt;p&gt;Every high-performing prompt is built from five ingredients. You won't always need all five — a simple question needs no ceremony. But when a prompt underperforms, the missing piece is almost always one of these.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.unsplash.com%2Fphoto-1586953208448-b95a79798f07%3Fw%3D1200%26auto%3Dformat%26fit%3Dcrop%26q%3D80" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.unsplash.com%2Fphoto-1586953208448-b95a79798f07%3Fw%3D1200%26auto%3Dformat%26fit%3Dcrop%26q%3D80" alt="Diagram showing the five components of a great prompt" width="1200" height="800"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  The Five Ingredients
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Ingredient&lt;/th&gt;
&lt;th&gt;What It Does&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;&lt;strong&gt;Role&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Sets vocabulary, depth, and assumptions&lt;/td&gt;
&lt;td&gt;&lt;em&gt;"Act as a senior UX researcher"&lt;/em&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Context&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Tells it the situation and goal&lt;/td&gt;
&lt;td&gt;&lt;em&gt;"I'm presenting this to a non-technical board"&lt;/em&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Format&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Defines the shape of the output&lt;/td&gt;
&lt;td&gt;&lt;em&gt;"Respond with a markdown table"&lt;/em&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Constraints&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Sets the guardrails&lt;/td&gt;
&lt;td&gt;&lt;em&gt;"Max 150 words. No jargon. No bullet points."&lt;/em&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Examples&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Shows what good looks like&lt;/td&gt;
&lt;td&gt;&lt;em&gt;"Here's a paragraph I wrote — match this tone"&lt;/em&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;The formula:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Role + Context + Format + Constraints + Examples = Exceptional Output
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The single biggest upgrade most people can make is simply replacing vague instructions with specific ones.&lt;/p&gt;

&lt;h3&gt;
  
  
  ❌ Vague vs ✅ Specific
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Vague:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Summarize this data for me.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Specific:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Summarize this sales data in 3 bullet points for a non-technical CEO.
Focus on month-over-month trends and flag one key risk.
Avoid jargon. Each bullet should be one sentence maximum.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Same task. Completely different output.&lt;/p&gt;




&lt;h3&gt;
  
  
  📊 How Output Quality Scales With Prompt Detail
&lt;/h3&gt;

&lt;p&gt;The more complete your prompt, the better your result — consistently, across every use case.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1 word only        ████░░░░░░░░░░  ~15% satisfying
1 sentence         █████████░░░░░  ~35% satisfying
+ Context added    █████████████░  ~58% satisfying
+ Format added     ████████████████░  ~74% satisfying
All 5 ingredients  ████████████████████  ~93% satisfying
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Estimated satisfaction rate based on prompt completeness&lt;/em&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  5 Universal Rules That Improve Any Prompt
&lt;/h3&gt;

&lt;p&gt;These work regardless of domain, tool, or task.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Use chain-of-thought&lt;/strong&gt;&lt;br&gt;
Add &lt;em&gt;"think step by step before answering."&lt;/em&gt; This single phrase dramatically improves accuracy on complex tasks because it forces the model to reason rather than pattern-match.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Assign a persona&lt;/strong&gt;&lt;br&gt;
&lt;em&gt;"You are an expert in X with 15 years of experience"&lt;/em&gt; primes the model to skip surface-level explanations and make expert-grade assumptions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Iterate rather than restart&lt;/strong&gt;&lt;br&gt;
The best results come from a conversation, not a single message. Start broad, then refine: &lt;em&gt;"Now shorten this to 150 words"&lt;/em&gt; or &lt;em&gt;"Rewrite the opening to be more direct."&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Declare your output format explicitly&lt;/strong&gt;&lt;br&gt;
&lt;em&gt;"Respond only with a JSON object"&lt;/em&gt; or &lt;em&gt;"Write in plain paragraphs — no bullet points"&lt;/em&gt; eliminates ambiguity and saves editing time.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. State what to avoid&lt;/strong&gt;&lt;br&gt;
&lt;em&gt;"Do not use passive voice," "Avoid recommending paid tools,"&lt;/em&gt; and &lt;em&gt;"Do not explain what you are about to do — just do it"&lt;/em&gt; are negative constraints that sharpen output significantly.&lt;/p&gt;




&lt;h2&gt;
  
  
  Part 2 — Prompting for Data Analysis
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;The dominant business AI use case worldwide&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.unsplash.com%2Fphoto-1551288049-bebda4e38f71%3Fw%3D1200%26auto%3Dformat%26fit%3Dcrop%26q%3D80" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.unsplash.com%2Fphoto-1551288049-bebda4e38f71%3Fw%3D1200%26auto%3Dformat%26fit%3Dcrop%26q%3D80" alt="Data visualization on a screen showing charts and graphs" width="1200" height="800"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;From startup founders parsing monthly revenue to enterprise analysts crunching millions of rows, data analysis is the most common professional AI task in the world today. The stakes are high: a misread data prompt doesn't just produce a weak paragraph — it produces a wrong conclusion that someone might act on.&lt;/p&gt;

&lt;p&gt;The key challenge: &lt;strong&gt;AI cannot see your spreadsheet unless you describe it.&lt;/strong&gt; You must hand the model your schema — column names, data types, and a few sample rows — before asking any question. Skipping this step is the single most common mistake in data prompting.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why Most Data Prompts Fail
&lt;/h3&gt;

&lt;p&gt;Most weak data prompts share three problems:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;They describe the goal but not the data structure&lt;/li&gt;
&lt;li&gt;They don't specify who needs to read the output&lt;/li&gt;
&lt;li&gt;They never ask the model to flag its own assumptions&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Those three gaps turn a potentially useful analysis into something confidently wrong.&lt;/p&gt;

&lt;h3&gt;
  
  
  Tips for Data Prompting
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;T1 — Lead with your schema&lt;/strong&gt;&lt;br&gt;
Before asking anything, describe your columns: name, type, and possible values. Paste two or three sample rows. This gives the model a working mental model of your actual data.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;T2 — Specify the audience for the insight&lt;/strong&gt;&lt;br&gt;
&lt;em&gt;"Explain this to a non-technical CEO"&lt;/em&gt; produces a narrative summary. &lt;em&gt;"Write this for a data scientist reviewing methodology"&lt;/em&gt; produces something far more technical. Same data, completely different output.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;T3 — Ask it to explain its reasoning first&lt;/strong&gt;&lt;br&gt;
&lt;em&gt;"Before answering, tell me which metrics you are using and why"&lt;/em&gt; catches faulty assumptions before they become errors in your report.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;T4 — Request explicit caveats&lt;/strong&gt;&lt;br&gt;
End every analysis prompt with: &lt;em&gt;"List any assumptions you are making and any data quality issues I should verify."&lt;/em&gt; This turns a confident-sounding answer into a transparent, trustworthy one.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;T5 — Layer your questions&lt;/strong&gt;&lt;br&gt;
Start with &lt;em&gt;"Describe the distribution of [column]"&lt;/em&gt; before jumping to &lt;em&gt;"Find the root cause of the Q3 revenue dip."&lt;/em&gt; Build shared understanding step by step.&lt;/p&gt;

&lt;h3&gt;
  
  
  🧪 World-Class Data Prompt Example
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;Role&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;    &lt;span class="n"&gt;Act&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="n"&gt;senior&lt;/span&gt; &lt;span class="n"&gt;business&lt;/span&gt; &lt;span class="n"&gt;intelligence&lt;/span&gt; &lt;span class="n"&gt;analyst&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="n"&gt;CSV&lt;/span&gt; &lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="n"&gt;these&lt;/span&gt; &lt;span class="n"&gt;columns&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
         &lt;span class="nf"&gt;order_id &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;string&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="nf"&gt;customer_id &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;string&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
         &lt;span class="nf"&gt;region &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;NA&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;EU&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;APAC&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="nf"&gt;product_sku &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;string&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
         &lt;span class="nf"&gt;revenue_usd &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;float&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="nf"&gt;order_date &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;YYYY&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;MM&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;DD&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
         &lt;span class="nf"&gt;churn_flag &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;Task&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;    &lt;span class="n"&gt;Identify&lt;/span&gt; &lt;span class="n"&gt;which&lt;/span&gt; &lt;span class="n"&gt;region&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;product_sku&lt;/span&gt; &lt;span class="n"&gt;combinations&lt;/span&gt;
         &lt;span class="n"&gt;carry&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;highest&lt;/span&gt; &lt;span class="n"&gt;churn&lt;/span&gt; &lt;span class="n"&gt;risk&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
         &lt;span class="n"&gt;Rank&lt;/span&gt; &lt;span class="n"&gt;them&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;explain&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;pattern&lt;/span&gt; &lt;span class="n"&gt;driving&lt;/span&gt; &lt;span class="n"&gt;each&lt;/span&gt; &lt;span class="n"&gt;one&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;

&lt;span class="n"&gt;Output&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;  &lt;span class="n"&gt;Python&lt;/span&gt; &lt;span class="n"&gt;code&lt;/span&gt; &lt;span class="n"&gt;using&lt;/span&gt; &lt;span class="n"&gt;pandas&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
         &lt;span class="n"&gt;Include&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="n"&gt;ranked&lt;/span&gt; &lt;span class="n"&gt;summary&lt;/span&gt; &lt;span class="n"&gt;table&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="n"&gt;bar&lt;/span&gt; &lt;span class="n"&gt;chart&lt;/span&gt;
         &lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="n"&gt;matplotlib&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="n"&gt;Comment&lt;/span&gt; &lt;span class="n"&gt;every&lt;/span&gt; &lt;span class="n"&gt;step&lt;/span&gt; &lt;span class="n"&gt;clearly&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;

&lt;span class="n"&gt;Caveats&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Do&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;assume&lt;/span&gt; &lt;span class="n"&gt;anything&lt;/span&gt; &lt;span class="n"&gt;about&lt;/span&gt; &lt;span class="n"&gt;missing&lt;/span&gt; &lt;span class="n"&gt;values&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
         &lt;span class="n"&gt;List&lt;/span&gt; &lt;span class="n"&gt;every&lt;/span&gt; &lt;span class="n"&gt;assumption&lt;/span&gt; &lt;span class="n"&gt;you&lt;/span&gt; &lt;span class="n"&gt;make&lt;/span&gt; &lt;span class="n"&gt;before&lt;/span&gt; &lt;span class="n"&gt;writing&lt;/span&gt; &lt;span class="n"&gt;code&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 — Prompting for Software Development
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;The highest-volume AI use case globally&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.unsplash.com%2Fphoto-1555066931-4365d14bab8c%3Fw%3D1200%26auto%3Dformat%26fit%3Dcrop%26q%3D80" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.unsplash.com%2Fphoto-1555066931-4365d14bab8c%3Fw%3D1200%26auto%3Dformat%26fit%3Dcrop%26q%3D80" alt="Code on a dark screen with colorful syntax highlighting" width="1200" height="800"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Developers are the most prolific AI users on the planet. AI has become the default co-pilot for writing boilerplate, debugging errors, reviewing pull requests, and scaffolding new features. Yet most engineers still leave enormous value on the table by prompting too vaguely.&lt;/p&gt;

&lt;p&gt;The core insight: &lt;strong&gt;context is everything.&lt;/strong&gt; The same function request written without a tech stack description produces generic, often unusable code. Written with a precise environment description, it produces something you can paste directly into production.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Context Stack Every Code Prompt Needs
&lt;/h3&gt;

&lt;p&gt;Think of briefing the AI like onboarding a contractor. Before writing a line of code, a good contractor asks:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What stack are we on?&lt;/li&gt;
&lt;li&gt;What conventions do we follow?&lt;/li&gt;
&lt;li&gt;What does the existing code look like?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Your prompt should answer all three before the model starts writing.&lt;/p&gt;

&lt;h3&gt;
  
  
  Tips for Code Prompting
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;T1 — Always name the language and version&lt;/strong&gt;&lt;br&gt;
&lt;em&gt;"Python 3.11," "TypeScript 5.3," "Go 1.22"&lt;/em&gt; — never assume the model will pick what you need. Version matters especially for Python, where async patterns and type hints differ significantly between releases.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;T2 — Paste the code you want improved&lt;/strong&gt;&lt;br&gt;
Never describe existing code when you can show it. Paste the function or module and say &lt;em&gt;"refactor this to..."&lt;/em&gt; rather than &lt;em&gt;"write a function that..."&lt;/em&gt; Real code beats descriptions every time.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;T3 — State your constraints upfront&lt;/strong&gt;&lt;br&gt;
&lt;em&gt;"No external libraries," "must run in a browser," "needs to handle 10 million rows without loading all into memory"&lt;/em&gt; — these completely change what good code looks like.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;T4 — Ask for tests alongside the code&lt;/strong&gt;&lt;br&gt;
&lt;em&gt;"Write the function AND a pytest test suite covering the happy path, edge cases, and error states"&lt;/em&gt; doubles your value per prompt and surfaces hidden logic assumptions before you ship them.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;T5 — Use the error-first technique for debugging&lt;/strong&gt;&lt;br&gt;
Paste the exact error message, the relevant code block, and your environment details. &lt;em&gt;"It doesn't work"&lt;/em&gt; wastes a turn. A full stack trace with context gets you a precise fix in one shot.&lt;/p&gt;

&lt;h3&gt;
  
  
  🧪 World-Class Coding Prompt Example
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;Stack&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;     &lt;span class="n"&gt;Python&lt;/span&gt; &lt;span class="mf"&gt;3.11&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;FastAPI&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;SQLAlchemy&lt;/span&gt; &lt;span class="mf"&gt;2.0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;PostgreSQL&lt;/span&gt;

&lt;span class="n"&gt;Task&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;      &lt;span class="n"&gt;Build&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="n"&gt;REST&lt;/span&gt; &lt;span class="n"&gt;endpoint&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;POST&lt;/span&gt; &lt;span class="o"&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="nb"&gt;id&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;deactivate&lt;/span&gt;
           &lt;span class="n"&gt;Soft&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;delete&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt; &lt;span class="n"&gt;by&lt;/span&gt; &lt;span class="n"&gt;setting&lt;/span&gt; &lt;span class="n"&gt;is_active&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="bp"&gt;False&lt;/span&gt;
           &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;deactivated_at&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;now&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;
           &lt;span class="n"&gt;Then&lt;/span&gt; &lt;span class="n"&gt;dispatch&lt;/span&gt; &lt;span class="n"&gt;an&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="n"&gt;confirmation&lt;/span&gt; &lt;span class="n"&gt;email&lt;/span&gt;
           &lt;span class="n"&gt;via&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="n"&gt;Celery&lt;/span&gt; &lt;span class="n"&gt;task&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;

&lt;span class="n"&gt;Rules&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;     &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;Must&lt;/span&gt; &lt;span class="n"&gt;be&lt;/span&gt; &lt;span class="nf"&gt;idempotent &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;safe&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="n"&gt;call&lt;/span&gt; &lt;span class="n"&gt;twice&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
           &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;Return&lt;/span&gt; &lt;span class="mi"&gt;404&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;found&lt;/span&gt;
           &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;Return&lt;/span&gt; &lt;span class="mi"&gt;409&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt; &lt;span class="ow"&gt;is&lt;/span&gt; &lt;span class="n"&gt;already&lt;/span&gt; &lt;span class="n"&gt;inactive&lt;/span&gt;
           &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;Use&lt;/span&gt; &lt;span class="n"&gt;ORM&lt;/span&gt; &lt;span class="n"&gt;only&lt;/span&gt; &lt;span class="err"&gt;—&lt;/span&gt; &lt;span class="n"&gt;no&lt;/span&gt; &lt;span class="n"&gt;raw&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;Follow&lt;/span&gt; &lt;span class="n"&gt;snake_case&lt;/span&gt; &lt;span class="n"&gt;naming&lt;/span&gt; &lt;span class="n"&gt;throughout&lt;/span&gt;

&lt;span class="n"&gt;Also&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;      &lt;span class="n"&gt;Write&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="n"&gt;pytest&lt;/span&gt; &lt;span class="n"&gt;suite&lt;/span&gt; &lt;span class="n"&gt;covering&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;happy&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;the&lt;/span&gt; &lt;span class="n"&gt;already&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;inactive&lt;/span&gt; &lt;span class="n"&gt;case&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="mi"&gt;404&lt;/span&gt; &lt;span class="n"&gt;case&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Part 4 — Prompting for Creative &amp;amp; Professional Writing
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;The most personal — and most misused — AI use case&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.unsplash.com%2Fphoto-1455390582262-044cdead277a%3Fw%3D1200%26auto%3Dformat%26fit%3Dcrop%26q%3D80" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.unsplash.com%2Fphoto-1455390582262-044cdead277a%3Fw%3D1200%26auto%3Dformat%26fit%3Dcrop%26q%3D80" alt="A person writing at a wooden desk with a notebook and coffee" width="1200" height="901"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Blog posts, marketing copy, cover letters, reports, social media, emails — writing is where AI gets used by the widest range of people. It's also where the gap between a mediocre prompt and a brilliant one is most visible.&lt;/p&gt;

&lt;p&gt;Generic AI writing is identifiable from a mile away. Writing produced from a carefully crafted prompt is indistinguishable from the real thing.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The core challenge:&lt;/strong&gt; AI defaults to a confident, neutral, mildly formal register. If that is not your voice, you must describe what you actually want — across three dimensions: &lt;em&gt;formality&lt;/em&gt;, &lt;em&gt;energy&lt;/em&gt;, and &lt;em&gt;personality&lt;/em&gt;. Vague tone instructions like &lt;em&gt;"make it friendly"&lt;/em&gt; change almost nothing.&lt;/p&gt;

&lt;h3&gt;
  
  
  Voice Is the Hardest Thing to Get Right — and the Most Important
&lt;/h3&gt;

&lt;p&gt;The fastest way to transfer your voice to AI is not to describe it — it's to demonstrate it. Paste a paragraph you have already written and say &lt;em&gt;"match this tone exactly."&lt;/em&gt; That single move eliminates more back-and-forth than any amount of adjective-based instruction.&lt;/p&gt;

&lt;h3&gt;
  
  
  Tips for Writing Prompts
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;T1 — Define the reader, not just the topic&lt;/strong&gt;&lt;br&gt;
&lt;em&gt;"A burnt-out product manager who reads on their commute and has no patience for waffle"&lt;/em&gt; is a far richer brief than &lt;em&gt;"a busy professional."&lt;/em&gt; The more specific your reader, the more targeted the writing.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;T2 — Name the emotion you want to create&lt;/strong&gt;&lt;br&gt;
&lt;em&gt;"Leave the reader feeling quietly motivated, not hyped"&lt;/em&gt; or &lt;em&gt;"aim for wry self-awareness, not earnest inspiration"&lt;/em&gt; is the kind of direction that separates good copy from great copy.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;T3 — Ban the clichés explicitly&lt;/strong&gt;&lt;br&gt;
List phrases to avoid: &lt;em&gt;"dive into," "game-changer," "in today's fast-paced world," "leverage," "unlock your potential," "journey."&lt;/em&gt; AI reaches for these by default. You have to close the door deliberately.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;T4 — Give it a structural scaffold&lt;/strong&gt;&lt;br&gt;
Tell it exactly how you want the piece to move: &lt;em&gt;"Open with a counter-intuitive claim. Spend the middle on one concrete story. Close with a single actionable takeaway."&lt;/em&gt; Structure beats length instructions every time.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;T5 — Ask for three versions&lt;/strong&gt;&lt;br&gt;
&lt;em&gt;"Give me three different opening paragraphs with three different emotional tones"&lt;/em&gt; costs nothing extra and gives you real creative options instead of forcing you to accept or reject a single draft.&lt;/p&gt;

&lt;h3&gt;
  
  
  🧪 World-Class Writing Prompt Example
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Goal:      Write a 600-word LinkedIn article on why most
           startup founders underinvest in operations.

Reader:    Series A founder, engineering background, 28–35.
           Reads fast, hates jargon, has heard every
           startup cliché and is immune to them.

Voice:     Direct, slightly wry, intellectually honest.
           Short paragraphs. Conversational but precise.
           No motivational-poster energy whatsoever.

Structure: 1. Hook: a counter-intuitive claim (2 sentences)
           2. The real problem — not the obvious one
           3. One concrete mini-story
           4. Three specific fixes
           5. Low-key, non-salesy close

Avoid:     "dive into", "game-changer", "journey",
           passive voice, any sentence over 25 words.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  The Takeaway — Prompt Like You Mean It
&lt;/h2&gt;

&lt;p&gt;The most common mistake people make with AI is treating it like a search engine: fire a query, read the result, move on. But AI is something fundamentally different — it's a collaborator that gets sharper the more context you give it, and better with every follow-up you send.&lt;/p&gt;

&lt;p&gt;You now have the full framework:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;✅ The &lt;strong&gt;five-part anatomy&lt;/strong&gt; that structures any prompt&lt;/li&gt;
&lt;li&gt;✅ &lt;strong&gt;Five universal rules&lt;/strong&gt; that improve every request&lt;/li&gt;
&lt;li&gt;✅ Deep playbooks for &lt;strong&gt;data analysis&lt;/strong&gt;, &lt;strong&gt;software development&lt;/strong&gt;, and &lt;strong&gt;creative writing&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;"You don't need to be a prompt engineer. You just need to be a clear thinker who communicates deliberately. That was always the skill worth having."&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;What separates the people getting remarkable results from those getting mediocre ones isn't access to a better model. It's the habit of investing fifteen extra seconds in a more thoughtful prompt.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Start with your next one.&lt;/strong&gt;&lt;/p&gt;




&lt;h1&gt;
  
  
  Rahul
&lt;/h1&gt;

&lt;p&gt;&lt;code&gt;Turning coffee into bugs&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;If this helped you, drop a ❤️ and follow for more practical guides — no hype, just things that actually work.&lt;/em&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  Tags
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;#ai&lt;/code&gt; &lt;code&gt;#productivity&lt;/code&gt; &lt;code&gt;#programming&lt;/code&gt; &lt;code&gt;#beginners&lt;/code&gt; &lt;code&gt;#tutorial&lt;/code&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>programming</category>
      <category>productivity</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Go Slices: Why Your Function Isn't Changing What You Think It Is</title>
      <dc:creator>Rahul</dc:creator>
      <pubDate>Sat, 21 Mar 2026 10:02:04 +0000</pubDate>
      <link>https://forem.com/rahul_t/go-slices-why-your-function-isnt-changing-what-you-think-it-is-3n9d</link>
      <guid>https://forem.com/rahul_t/go-slices-why-your-function-isnt-changing-what-you-think-it-is-3n9d</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;5 min read&lt;/strong&gt; · Beginner-friendly · Real code you can paste into &lt;a href="https://go.dev/play/" rel="noopener noreferrer"&gt;Go Playground&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  The bug that confuses every Go beginner
&lt;/h2&gt;

&lt;p&gt;You pass your slice to a function. The function changes some values. You print the slice back in &lt;code&gt;main&lt;/code&gt;... and some changes are there, some aren't.&lt;/p&gt;

&lt;p&gt;Sound familiar? This article explains &lt;em&gt;exactly&lt;/em&gt; why — with diagrams, not walls of text.&lt;/p&gt;




&lt;h2&gt;
  
  
  Our data — a fleet of vehicles
&lt;/h2&gt;

&lt;p&gt;Two structs, one slice. Everything in this article uses these types.&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;VehicleType&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;TwoWheeler&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ThreeWheeler&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;FourWheeler&lt;/span&gt; &lt;span class="kt"&gt;bool&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="n"&gt;Vehicle&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;Model&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Color&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;
    &lt;span class="n"&gt;Type&lt;/span&gt;         &lt;span class="n"&gt;VehicleType&lt;/span&gt;  &lt;span class="c"&gt;// nested by value — not a pointer&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="n"&gt;Fleet&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="n"&gt;Vehicle&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Fill it with two vehicles:&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;fleet&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;Fleet&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;Model&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Bike"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Color&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Red"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="n"&gt;Type&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;VehicleType&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;TwoWheeler&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="n"&gt;Model&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Car"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="n"&gt;Color&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Blue"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Type&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;VehicleType&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;FourWheeler&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  What is a slice? (the sticky note model)
&lt;/h2&gt;

&lt;p&gt;Before anything else, burn this mental model in — a slice variable is just a &lt;strong&gt;3-field sticky note&lt;/strong&gt;. The real data lives on the heap.&lt;/p&gt;

&lt;p&gt;&lt;a href="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%2Facfh7bg0401bxbdajliy.png" class="article-body-image-wrapper"&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%2Facfh7bg0401bxbdajliy.png" alt="A slice is just a sticky note pointing to the real data on the heap" width="800" height="310"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When you pass &lt;code&gt;fleet&lt;/code&gt; to a function, Go copies the &lt;strong&gt;sticky note&lt;/strong&gt; — not the parking lot.&lt;/p&gt;




&lt;h2&gt;
  
  
  Pass by value — a photocopy of the sticky note
&lt;/h2&gt;

&lt;p&gt;The function gets its own header copy. Both copies point at the same backing array.&lt;/p&gt;

&lt;p&gt;&lt;a href="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%2Fckh5r5v67yq6aiurcieb.png" class="article-body-image-wrapper"&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%2Fckh5r5v67yq6aiurcieb.png" alt="Pass by value — two headers sharing one backing array. Element mutations are visible, append is not." width="800" height="420"&gt;&lt;/a&gt;&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;byValue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fleet&lt;/span&gt; &lt;span class="n"&gt;Fleet&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;fleet&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="n"&gt;Color&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Green"&lt;/span&gt;         &lt;span class="c"&gt;// ✅ writes to shared heap — caller SEES it&lt;/span&gt;
    &lt;span class="n"&gt;fleet&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="n"&gt;Type&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;TwoWheeler&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;false&lt;/span&gt;  &lt;span class="c"&gt;// ✅ nested struct is on the heap too&lt;/span&gt;
    &lt;span class="n"&gt;fleet&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;fleet&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Vehicle&lt;/span&gt;&lt;span class="p"&gt;{})&lt;/span&gt;  &lt;span class="c"&gt;// ❌ updates ONLY the function's copy of len&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;What the caller sees after &lt;code&gt;byValue(fleet)&lt;/code&gt;:&lt;/strong&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Action&lt;/th&gt;
&lt;th&gt;Visible to caller?&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;fleet[0].Color&lt;/code&gt; → "Green"&lt;/td&gt;
&lt;td&gt;✅ Yes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;fleet[0].Type.TwoWheeler&lt;/code&gt; → false&lt;/td&gt;
&lt;td&gt;✅ Yes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;len(fleet)&lt;/code&gt; → 3 from append&lt;/td&gt;
&lt;td&gt;❌ No — still 2&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;blockquote&gt;
&lt;p&gt;💡 &lt;strong&gt;Seems quite easy:&lt;/strong&gt; Repainting a car already in the lot? Everyone sees it. Driving a new car into YOUR copy of the address? The owner's map still shows 2 cars.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Pass by reference — handing over the key
&lt;/h2&gt;

&lt;p&gt;Pass &lt;code&gt;*Fleet&lt;/code&gt; so the function can update the caller's header — including length.&lt;/p&gt;

&lt;p&gt;&lt;a href="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%2Fcibe5y9fv4aapunu8dv3.png" class="article-body-image-wrapper"&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%2Fcibe5y9fv4aapunu8dv3.png" alt="Pass by reference — pointer to the slice header, all changes including append are visible to caller" width="800" height="360"&gt;&lt;/a&gt;&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;byRef&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fleet&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;Fleet&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;fleet&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="n"&gt;Color&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Yellow"&lt;/span&gt;       &lt;span class="c"&gt;// ✅ visible to caller&lt;/span&gt;
    &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;fleet&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;fleet&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Vehicle&lt;/span&gt;&lt;span class="p"&gt;{})&lt;/span&gt; &lt;span class="c"&gt;// ✅ len change visible to caller too&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;// call it:&lt;/span&gt;
&lt;span class="n"&gt;byRef&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;fleet&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;What the caller sees after &lt;code&gt;byRef(&amp;amp;fleet)&lt;/code&gt;:&lt;/strong&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Action&lt;/th&gt;
&lt;th&gt;Visible to caller?&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;fleet[0].Color&lt;/code&gt; → "Yellow"&lt;/td&gt;
&lt;td&gt;✅ Yes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;len(fleet)&lt;/code&gt; → 3 from append&lt;/td&gt;
&lt;td&gt;✅ Yes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;New vehicle at &lt;code&gt;fleet[2]&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;✅ Yes&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;blockquote&gt;
&lt;p&gt;🔑 &lt;strong&gt;As simple as that:&lt;/strong&gt; You handed the function the actual key to the parking office. It can repaint cars AND add new bays — and you'll see all of it.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Deep clone — two completely separate parking lots
&lt;/h2&gt;

&lt;p&gt;Need zero shared state? Use &lt;code&gt;copy()&lt;/code&gt; to build a brand-new backing array.&lt;/p&gt;

&lt;p&gt;&lt;a href="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%2F7yrj3edjgn1b1vrxcpct.png" class="article-body-image-wrapper"&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%2F7yrj3edjgn1b1vrxcpct.png" alt="Deep clone using copy() — two completely independent backing arrays, no shared memory" width="800" height="316"&gt;&lt;/a&gt;&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;clone&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;Fleet&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;fleet&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;clone&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;fleet&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;           &lt;span class="c"&gt;// new backing array at a new address&lt;/span&gt;
&lt;span class="n"&gt;clone&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="n"&gt;Color&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Purple"&lt;/span&gt;    &lt;span class="c"&gt;// original fleet untouched ✅&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;🧬 &lt;strong&gt;When to use this:&lt;/strong&gt; Sorting or filtering for display, transforming data for an API response, or any time changes must not affect the source slice.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Quick reference
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Action&lt;/th&gt;
&lt;th&gt;Pass by Value&lt;/th&gt;
&lt;th&gt;Pass by Reference&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;fleet[0].Color = ...&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;✅ Caller sees it&lt;/td&gt;
&lt;td&gt;✅ Caller sees it&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;fleet[0].Type.X = ...&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;✅ Caller sees it&lt;/td&gt;
&lt;td&gt;✅ Caller sees it&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;append(fleet, vehicle)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;❌ NOT visible&lt;/td&gt;
&lt;td&gt;✅ Caller sees it&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  3 rules — commit these to memory
&lt;/h2&gt;

&lt;p&gt;&lt;a href="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%2Fl4tmhmbj7txw10la1h4l.png" class="article-body-image-wrapper"&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%2Fl4tmhmbj7txw10la1h4l.png" alt="Three rules to remember forever about Go slices" width="800" height="230"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Rule 1 ✅&lt;/strong&gt; — Mutate existing element → always visible, value or pointer.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Rule 2 ⚠️&lt;/strong&gt; — &lt;code&gt;append&lt;/code&gt; → only visible when you pass &lt;code&gt;*Fleet&lt;/code&gt; (pointer).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Rule 3 🧬&lt;/strong&gt; — Total isolation → use &lt;code&gt;copy()&lt;/code&gt; for a brand-new backing array.&lt;/p&gt;




&lt;h2&gt;
  
  
  Full runnable example
&lt;/h2&gt;

&lt;p&gt;Paste this into &lt;a href="https://go.dev/play/" rel="noopener noreferrer"&gt;Go Playground&lt;/a&gt; and run 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;package&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="s"&gt;"fmt"&lt;/span&gt;

&lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="n"&gt;VehicleType&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;TwoWheeler&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ThreeWheeler&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;FourWheeler&lt;/span&gt; &lt;span class="kt"&gt;bool&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="n"&gt;Vehicle&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;Model&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Color&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;
    &lt;span class="n"&gt;Type&lt;/span&gt;         &lt;span class="n"&gt;VehicleType&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="n"&gt;Fleet&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="n"&gt;Vehicle&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;byValue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt; &lt;span class="n"&gt;Fleet&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;f&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="n"&gt;Color&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Green"&lt;/span&gt;      &lt;span class="c"&gt;// ✅ visible to caller&lt;/span&gt;
    &lt;span class="n"&gt;f&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;f&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Vehicle&lt;/span&gt;&lt;span class="p"&gt;{})&lt;/span&gt;  &lt;span class="c"&gt;// ❌ NOT visible to caller&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;byRef&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;Fleet&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;f&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="n"&gt;Color&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Yellow"&lt;/span&gt;   &lt;span class="c"&gt;// ✅ visible to caller&lt;/span&gt;
    &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;f&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;f&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Vehicle&lt;/span&gt;&lt;span class="p"&gt;{})&lt;/span&gt; &lt;span class="c"&gt;// ✅ visible to caller&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;fleet&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;Fleet&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;Model&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Bike"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Color&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Red"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="n"&gt;Type&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;VehicleType&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;TwoWheeler&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="n"&gt;Model&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Car"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="n"&gt;Color&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Blue"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Type&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;VehicleType&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;FourWheeler&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="n"&gt;byValue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fleet&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;fleet&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="n"&gt;Color&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;fleet&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="c"&gt;// Green 2&lt;/span&gt;

    &lt;span class="n"&gt;byRef&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;fleet&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;fleet&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="n"&gt;Color&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;fleet&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="c"&gt;// Yellow 3&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  What about the nested VehicleType?
&lt;/h2&gt;

&lt;p&gt;Because &lt;code&gt;VehicleType&lt;/code&gt; is embedded &lt;strong&gt;by value&lt;/strong&gt; inside &lt;code&gt;Vehicle&lt;/code&gt; (not a pointer), it lives contiguously in memory with the rest of the struct. No special rules — it copies and mutates exactly like any other field.&lt;/p&gt;

&lt;p&gt;If it were a pointer (&lt;code&gt;Type *VehicleType&lt;/code&gt;), that would be a different story — but that's a topic for another article.&lt;/p&gt;




&lt;h1&gt;
  
  
  Rahul
&lt;/h1&gt;

&lt;p&gt;&lt;code&gt;Turning coffee into bugs&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;My first blog, found this useful? Let me know in comments.&lt;/em&gt; &lt;/p&gt;




</description>
      <category>go</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
