<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>golang on Saurabh Kumar</title><link>https://saurabh-kumar.com/tags/golang/</link><description>Recent content in golang on Saurabh Kumar</description><generator>Hugo</generator><language>en-US</language><copyright>Copyright © 2025, Saurabh Kumar.</copyright><lastBuildDate>Sun, 19 Jul 2026 12:00:00 +0000</lastBuildDate><atom:link href="https://saurabh-kumar.com/tags/golang/index.xml" rel="self" type="application/rss+xml"/><item><title>Go interfaces are implicit: a type satisfies an interface by having the right…</title><link>https://saurabh-kumar.com/til/1784462400/</link><pubDate>Sun, 19 Jul 2026 12:00:00 +0000</pubDate><guid>https://saurabh-kumar.com/til/1784462400/</guid><description>&lt;p&gt;Go interfaces are implicit: a type satisfies an interface by having the right methods, no &lt;code&gt;implements&lt;/code&gt; keyword.&lt;/p&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;Closest Python equivalent is &lt;code&gt;typing.Protocol&lt;/code&gt; (structural subtyping, checked by mypy), but Go enforces it at compile time, not via a separate type checker.&lt;/li&gt;&#10;&lt;li&gt;Sharp edge: a nil concrete pointer wrapped in an interface value is not &lt;code&gt;nil&lt;/code&gt;. &lt;code&gt;var dog *Dog = nil; var s Speaker = dog&lt;/code&gt; gives &lt;code&gt;s != nil&lt;/code&gt; because the interface holds &lt;code&gt;(*Dog, nil)&lt;/code&gt;, a typed pair. Bites hardest when returning &lt;code&gt;error&lt;/code&gt; interfaces.&lt;/li&gt;&#10;&lt;li&gt;Go proverb: &amp;ldquo;the bigger the interface, the weaker the abstraction.&amp;rdquo; Keep them to 1-3 methods, define where consumed not where implemented.&lt;/li&gt;&#10;&lt;/ul&gt;&#10;</description></item></channel></rss>