<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Learn-Go on sugar, spice, &amp;terminal? nice</title>
    <link>https://terminal.space/tag/learn-go/</link>
    <description>Recent content in Learn-Go on sugar, spice, &amp;terminal? nice</description>
    <generator>Hugo</generator>
    <language>en</language>
    <lastBuildDate>Tue, 11 Jan 2022 08:48:23 +0000</lastBuildDate>
    <atom:link href="https://terminal.space/tag/learn-go/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Interfaces in golang</title>
      <link>https://terminal.space/tech/interfaces-in-golang/</link>
      <pubDate>Tue, 11 Jan 2022 08:48:23 +0000</pubDate>
      <guid>https://terminal.space/tech/interfaces-in-golang/</guid>
      <description>&lt;h2 id=&#34;tldr&#34;&gt;TL;DR:&lt;/h2&gt;&#xA;&lt;p&gt;An interface just defines a collection of methods. When you create an instance, it&amp;rsquo;s just a wrapper around a concrete type. In addition to the concrete type, the interface contains an extra array of function pointers. These function pointers correspond to each method in the interface that the concrete type implements&lt;/p&gt;&#xA;&lt;h2 id=&#34;first-a-detour&#34;&gt;First, a detour&lt;/h2&gt;&#xA;&lt;p&gt;Let&amp;rsquo;s define a custom type, and some methods that go with it:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;package main&#xA;&#xA;import &amp;#34;fmt&amp;#34;&#xA;&#xA;type ComputerProgrammer string&#xA;&#xA;func (c ComputerProgrammer) Greet(name string) string {&#xA;&#x9;return string(c) + &amp;#34;: hello, &amp;#34; + name&#xA;}&#xA;&#xA;func (c ComputerProgrammer) Walk(distance int) int {&#xA;&#x9;return len(c) + distance&#xA;}&#xA;&#xA;func main() {&#xA;&#x9;a := ComputerProgrammer(&amp;#34;golang&amp;#34;)&#xA;&#x9;fmt.Println(a.Greet(&amp;#34;world&amp;#34;), a.Walk(5))&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;When go compiles this code, it generates a function similar to this:&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
