<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Go Generics Masterclass on Atharva Pandey</title><link>https://atharva.page/series/go-generics-masterclass/</link><description>Recent content in Go Generics Masterclass on Atharva Pandey</description><generator>Hugo</generator><language>en-us</language><copyright>Copyright ©</copyright><lastBuildDate>Sun, 17 Nov 2024 00:00:00 +0000</lastBuildDate><atom:link href="https://atharva.page/series/go-generics-masterclass/index.xml" rel="self" type="application/rss+xml"/><item><title>Lesson 8: When Duplication Is Better Than Abstraction — Bad abstraction costs more than repeated code</title><link>https://atharva.page/post/go/go-generics-duplication-vs-abstraction/</link><pubDate>Sun, 17 Nov 2024 00:00:00 +0000</pubDate><guid>https://atharva.page/post/go/go-generics-duplication-vs-abstraction/</guid><description>&lt;p&gt;I want to end this course with the idea I wish I&amp;rsquo;d understood at the start — not just intellectually, but in my gut. It&amp;rsquo;s this: &lt;strong&gt;duplication is a problem you can see. Bad abstraction is a problem you can&amp;rsquo;t see until it&amp;rsquo;s too late.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Duplicated code is visible. You grep for it, you find it, you fix it. It&amp;rsquo;s annoying, but it&amp;rsquo;s honest. Bad abstraction hides behind clean-looking code. It&amp;rsquo;s the function that requires fifteen minutes of context to understand, the type parameter that nobody knows how to satisfy, the constraint that&amp;rsquo;s technically correct but practically useless. It costs you in onboarding, in debugging, in every change that touches it for the rest of the codebase&amp;rsquo;s life.&lt;/p&gt;</description></item><item><title>Lesson 7: Refactoring Concrete to Generic — Start concrete, extract when proven</title><link>https://atharva.page/post/go/go-generics-refactoring/</link><pubDate>Fri, 25 Oct 2024 00:00:00 +0000</pubDate><guid>https://atharva.page/post/go/go-generics-refactoring/</guid><description>&lt;p&gt;The advice &amp;ldquo;start concrete, extract when proven&amp;rdquo; is easy to say and surprisingly hard to follow when you&amp;rsquo;re in the middle of writing the third version of the same function. The temptation to generalize early is real. I&amp;rsquo;ve felt it. Most engineers who care about clean code have felt it.&lt;/p&gt;
&lt;p&gt;But the cost of premature abstraction is higher than the cost of temporary duplication. A duplicated function can be removed with a search-and-replace. A bad abstraction gets built around, extended in wrong directions, and defended by sunk-cost thinking. This lesson is about how to do the refactoring correctly — waiting until the pattern is proven, then extracting it cleanly.&lt;/p&gt;</description></item><item><title>Lesson 6: Real-World Examples — Generics that survived code review</title><link>https://atharva.page/post/go/go-generics-real-world/</link><pubDate>Wed, 02 Oct 2024 00:00:00 +0000</pubDate><guid>https://atharva.page/post/go/go-generics-real-world/</guid><description>&lt;p&gt;Lessons 1 through 5 were mostly about principles. This one is about code. Specifically, the five generic implementations I&amp;rsquo;ve used in real production systems that my teammates didn&amp;rsquo;t complain about. Each one passed code review, made it into production, and held up over time.&lt;/p&gt;
&lt;p&gt;The pattern across all of them is consistent: the algorithm is identical regardless of the type, the duplication without generics would have been mechanical and ongoing, and the generic version is genuinely easier to read than the alternative.&lt;/p&gt;</description></item><item><title>Lesson 5: Anti-Patterns — Just because you can doesn't mean you should</title><link>https://atharva.page/post/go/go-generics-anti-patterns/</link><pubDate>Sun, 08 Sep 2024 00:00:00 +0000</pubDate><guid>https://atharva.page/post/go/go-generics-anti-patterns/</guid><description>&lt;p&gt;Every powerful tool has a failure mode that looks like success. With generics, the failure mode is this: you write something that compiles, works correctly, and is impressively abstract — but your teammates can&amp;rsquo;t read it, can&amp;rsquo;t debug it, and quietly work around it. I&amp;rsquo;ve written code like that. It felt clever in the moment. It was a problem in practice.&lt;/p&gt;
&lt;p&gt;This lesson is about the patterns that sound good and turn out badly. I&amp;rsquo;m calling them out explicitly because they&amp;rsquo;re seductive — especially if you&amp;rsquo;ve spent time in Haskell or Scala and you know what generic abstractions &lt;em&gt;can&lt;/em&gt; look like.&lt;/p&gt;</description></item><item><title>Lesson 4: Interfaces vs Generics — Behavior or data shape? That's your answer</title><link>https://atharva.page/post/go/go-generics-interfaces-vs-generics/</link><pubDate>Wed, 14 Aug 2024 00:00:00 +0000</pubDate><guid>https://atharva.page/post/go/go-generics-interfaces-vs-generics/</guid><description>&lt;p&gt;One of the most common mistakes I see in Go codebases post-1.18 is people reaching for generics when interfaces were already the right tool — and vice versa. The two features look superficially similar. Both let you write code that works with multiple types. But they&amp;rsquo;re solving different problems, and using the wrong one makes code harder to read, test, and extend.&lt;/p&gt;
&lt;p&gt;Here&amp;rsquo;s the question I ask myself every time: &lt;strong&gt;Is what varies the behavior, or the data shape?&lt;/strong&gt; That single question gets me to the right answer ninety percent of the time.&lt;/p&gt;</description></item><item><title>Lesson 3: Good Patterns — Generic code should be boring</title><link>https://atharva.page/post/go/go-generics-good-patterns/</link><pubDate>Mon, 22 Jul 2024 00:00:00 +0000</pubDate><guid>https://atharva.page/post/go/go-generics-good-patterns/</guid><description>&lt;p&gt;The best generic code I&amp;rsquo;ve ever written looks like the worst. No clever type wizardry, no five-level constraint hierarchies — just a function that clearly does one thing, works for any type that makes sense, and disappears into the background of a codebase. When someone reads it two years later and immediately understands it, that&amp;rsquo;s a win.&lt;/p&gt;
&lt;p&gt;This lesson is about the patterns where generics genuinely shine. These are the ones that survived code review, that made the team&amp;rsquo;s lives measurably better, and that I&amp;rsquo;d reach for again without hesitation.&lt;/p&gt;</description></item><item><title>Lesson 2: Type Parameters and Constraints — Teaching the compiler what you mean</title><link>https://atharva.page/post/go/go-generics-type-parameters/</link><pubDate>Mon, 01 Jul 2024 00:00:00 +0000</pubDate><guid>https://atharva.page/post/go/go-generics-type-parameters/</guid><description>&lt;p&gt;The hardest part of learning Go generics isn&amp;rsquo;t the concept — it&amp;rsquo;s the syntax. The first time I read a function signature like &lt;code&gt;func Keys[K comparable, V any](m map[K]V) []K&lt;/code&gt;, I did a double-take. It looks like someone snuck type annotations from another language into Go. But once it clicks, it&amp;rsquo;s actually pretty elegant — every piece is there for a reason.&lt;/p&gt;
&lt;p&gt;This lesson is about understanding type parameters and constraints deeply enough that you can write them yourself without copying from examples. That&amp;rsquo;s the threshold that separates &amp;ldquo;I&amp;rsquo;ve used generics&amp;rdquo; from &amp;ldquo;I understand generics.&amp;rdquo;&lt;/p&gt;</description></item><item><title>Lesson 1: What Generics Solve in Go — Remove duplication without hiding intent</title><link>https://atharva.page/post/go/go-generics-what-they-solve/</link><pubDate>Fri, 07 Jun 2024 00:00:00 +0000</pubDate><guid>https://atharva.page/post/go/go-generics-what-they-solve/</guid><description>&lt;p&gt;I spent two years writing Go before generics shipped in 1.18, and I&amp;rsquo;ll be honest — I didn&amp;rsquo;t miss them at first. Go&amp;rsquo;s simplicity felt like a feature. Then I found myself maintaining a codebase with six nearly-identical sort functions, a &lt;code&gt;MinInt&lt;/code&gt;, &lt;code&gt;MinFloat64&lt;/code&gt;, &lt;code&gt;MinInt64&lt;/code&gt;, and a comment that said &amp;ldquo;do not touch, generated.&amp;rdquo; That&amp;rsquo;s when I started caring.&lt;/p&gt;
&lt;p&gt;Generics in Go aren&amp;rsquo;t a revolution. They&amp;rsquo;re a targeted fix for a specific, real pain point: you had to either use &lt;code&gt;interface{}&lt;/code&gt; and lose type safety, or repeat yourself across every concrete type you cared about. Neither option aged well.&lt;/p&gt;</description></item></channel></rss>