<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Chapter 8 Generics on Go: Under the Hood</title><link>https://golang.design/under-the-hood/en/part2lang/ch08generics/</link><description>Recent content in Chapter 8 Generics on Go: Under the Hood</description><generator>Hugo</generator><language>en</language><atom:link href="https://golang.design/under-the-hood/en/part2lang/ch08generics/index.xml" rel="self" type="application/rss+xml"/><item><title>8.1 The Evolution of Generics Design</title><link>https://golang.design/under-the-hood/en/part2lang/ch08generics/history/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://golang.design/under-the-hood/en/part2lang/ch08generics/history/</guid><description>&lt;h1 id="81-the-evolution-of-generics-design"&gt;8.1 The Evolution of Generics Design&lt;/h1&gt;
&lt;p&gt;Generics is the feature Go waited longest for, argued about most fiercely, and that best embodies its design philosophy. From the open-source release in 2009 to its arrival in Go 1.18 in 2022, the thirteen years of hesitation and the eventual choices are themselves a lesson in language design. This section answers three questions: why Go held off on generics for so long, how it finally added them, and how they are implemented underneath. The last question matters most, because Go&amp;rsquo;s implementation copies no existing precedent and instead takes a distinctive middle road, and it is that road that is Go&amp;rsquo;s real answer to the thirteen-year problem. How the design itself evolved along the way (contracts, type sets, several rounds of syntax proposals) is left to &lt;a href=".././future"&gt;8.4&lt;/a&gt;; this section takes only the skeleton.&lt;/p&gt;</description></item><item><title>8.2 Contract-Based Generics</title><link>https://golang.design/under-the-hood/en/part2lang/ch08generics/contracts/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://golang.design/under-the-hood/en/part2lang/ch08generics/contracts/</guid><description>&lt;h1 id="82-contract-based-generics"&gt;8.2 Contract-Based Generics&lt;/h1&gt;
&lt;blockquote&gt;
&lt;p&gt;This section has a companion online talk: &lt;a href="https://www.youtube.com/watch?v=E16Y6bI2S08"&gt;on YouTube&lt;/a&gt;,
&lt;a href="https://changkun.de/s/go2generics/"&gt;Google Slides deck&lt;/a&gt;. The deck was recorded in 2019, while the contracts
proposal was still under discussion, and it corroborates this section.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;a href=".././history"&gt;8.1&lt;/a&gt; glossed over the evolution &amp;ldquo;contracts came first, then a turn toward interfaces as constraints&amp;rdquo;
in a single sentence. This section unfolds that sentence: what contracts actually looked like, how much expressive
power they had, and why they were ultimately abandoned. This rejected design is not historical waste; it explains
where today&amp;rsquo;s &lt;code&gt;[T Ordered]&lt;/code&gt; syntax came from, and it illustrates a move that recurs throughout Go&amp;rsquo;s design: first
produce a highly expressive but somewhat complex scheme, then turn back and ask &amp;ldquo;can this be expressed with concepts
we already have&amp;rdquo;, forcing complexity to earn its right to exist.&lt;/p&gt;</description></item><item><title>8.3 Type-Checking Techniques</title><link>https://golang.design/under-the-hood/en/part2lang/ch08generics/checker/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://golang.design/under-the-hood/en/part2lang/ch08generics/checker/</guid><description>&lt;h1 id="83-type-checking-techniques"&gt;8.3 Type-Checking Techniques&lt;/h1&gt;
&lt;p&gt;Generics pose a far harder problem to the type checker than before. The old judgment had only one shape: &amp;ldquo;is this value of this type?&amp;rdquo; With type parameters, the checker now has to answer three new questions: whether a type argument satisfies a constraint, whether an operation like &lt;code&gt;a + b&lt;/code&gt; is valid on an unknown type, and what that unwritten &lt;code&gt;T&lt;/code&gt; actually is when you call &lt;code&gt;Max(3, 5)&lt;/code&gt;. These three concerns correspond to the three topics of this section: type sets, core types, and type inference. They are where the design from &lt;a href=".././history"&gt;8.1&lt;/a&gt; lands as concrete compile-time technique, and they are also a prelude to the front end of &lt;a href="https://golang.design/under-the-hood/en/part5toolchain/ch15compile/"&gt;15 The Compiler&lt;/a&gt;.&lt;/p&gt;</description></item><item><title>8.4 The Future of Generics</title><link>https://golang.design/under-the-hood/en/part2lang/ch08generics/future/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://golang.design/under-the-hood/en/part2lang/ch08generics/future/</guid><description>&lt;h1 id="84-the-future-of-generics"&gt;8.4 The Future of Generics&lt;/h1&gt;
&lt;blockquote&gt;
&lt;p&gt;Generics landed in 1.18 and more than four years have passed. This section no longer dwells on
speculation about &amp;ldquo;what might be.&amp;rdquo; Instead it looks back and takes inventory: which expectations
were met, which were deliberately shelved, and where the tension that runs through it all (the
cost of abstraction) stands today. The author once gave a public talk on Go 2 generics in earlier
years (&lt;a href="https://www.youtube.com/watch?v=E16Y6bI2S08"&gt;YouTube&lt;/a&gt;,
&lt;a href="https://changkun.de/s/go2generics/"&gt;slides&lt;/a&gt;). Most of those predictions can now be checked against
reality, and this section accounts for them along the way.&lt;/p&gt;</description></item></channel></rss>