<?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>DEV Community: Ben McNicholl</title>
    <description>The latest articles on DEV Community by Ben McNicholl (@mcncl).</description>
    <link>https://dev.to/mcncl</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%2F191680%2F8d86b974-0941-4a3b-b22b-a84d63615816.jpeg</url>
      <title>DEV Community: Ben McNicholl</title>
      <link>https://dev.to/mcncl</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mcncl"/>
    <language>en</language>
    <item>
      <title>25 Days to Release a Game</title>
      <dc:creator>Ben McNicholl</dc:creator>
      <pubDate>Tue, 05 Nov 2019 06:25:27 +0000</pubDate>
      <link>https://dev.to/mcncl/25-days-to-release-a-game-5c0b</link>
      <guid>https://dev.to/mcncl/25-days-to-release-a-game-5c0b</guid>
      <description>&lt;p&gt;I've decided I need to brush up on my Python, so I've opted to take part in this year's &lt;a href="https://itch.io/jam/game-off-2019"&gt;Game Off&lt;/a&gt;, GitHub and itch.io's annual competition for game developers, or aspiring ones. &lt;/p&gt;

&lt;p&gt;This year's theme is &lt;strong&gt;leaps and bounds&lt;/strong&gt;, for which I already have a couple of ideas.&lt;/p&gt;

&lt;p&gt;There really isn't a huge need to read this post, so I'll end it here. It's just an effort to make my plans public to ensure I stick with it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--OiZzD4a0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/rkha1ccttrm0gc4kozvz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--OiZzD4a0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/rkha1ccttrm0gc4kozvz.png" alt="Countdown to GitHub GameOff"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>python</category>
      <category>gameoff</category>
      <category>github</category>
    </item>
    <item>
      <title>A [Very] Simple Approach to Pointers in Go</title>
      <dc:creator>Ben McNicholl</dc:creator>
      <pubDate>Fri, 11 Oct 2019 23:45:04 +0000</pubDate>
      <link>https://dev.to/mcncl/a-simple-approach-to-pointers-in-go-471j</link>
      <guid>https://dev.to/mcncl/a-simple-approach-to-pointers-in-go-471j</guid>
      <description>&lt;p&gt;This is in no way an all encompassing view on pointers, and there are one or two areas where the explanation in this post doesn't quite cut the mustard, but I found it much easier to view pointers in this way, so thought I'd share.&lt;/p&gt;

&lt;p&gt;Pointers can be tricky to understand. They are used mostly when we want to &lt;strong&gt;overwrite&lt;/strong&gt; some data, rather than using Go's inbuilt actions of making a &lt;strong&gt;copy&lt;/strong&gt; of some data once we decide to modify it (by default, Go passes by value). &lt;/p&gt;

&lt;p&gt;Anything which is a &lt;strong&gt;value&lt;/strong&gt; type will utilise Go's inbuilt copying functionality, in order to preserve the data. Anything which is a &lt;strong&gt;reference&lt;/strong&gt; type object will be modifiable and will overwrite original data.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;amp;&lt;/code&gt; refers to the address of a value&lt;br&gt;
&lt;code&gt;*&lt;/code&gt; refers to the value at that address&lt;/p&gt;

&lt;p&gt;For example;&lt;br&gt;
&lt;/p&gt;

&lt;div class="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;house&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;occupant&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;houseLocation&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;house&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;changeTenant&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;newTenant&lt;/span&gt; &lt;span class="kt"&gt;string&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;houseLocation&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;occupant&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;newTenant&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;bensHouse&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;house&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;occupant&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Ben"&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;Printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"The tenant is: %v &lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;bensHouse&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;houseAddress&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;bensHouse&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="s"&gt;"Changing tenant....."&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;houseAddress&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;changeTenant&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Paul"&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;Printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"The tenant is: %v &lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;bensHouse&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;p&gt;Let's start with the &lt;strong&gt;main&lt;/strong&gt; block.&lt;/p&gt;

&lt;p&gt;bensHouse is of &lt;code&gt;type&lt;/code&gt; &lt;em&gt;house&lt;/em&gt; and has one occupant, me (Ben).&lt;/p&gt;

&lt;p&gt;Now, my landlord owns 100 houses (he lives on a tropical island, drinking cold beers all day). The rental agency cannot ring him and say "there is an issue with Ben's house", he doesn't know which one that is! Instead, they have to get the address of my house, they do that using &lt;code&gt;&amp;amp;bensHouse&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;So, the value at houseAddress might now be:&lt;/p&gt;

&lt;p&gt;35 Winecask Road&lt;br&gt;
Richmond&lt;br&gt;
Melbourne&lt;br&gt;
3012&lt;br&gt;
Australia&lt;/p&gt;

&lt;p&gt;The rental agency needs to change the tenant, as I'm moving out. They do that by running the &lt;code&gt;changeTenant&lt;/code&gt; function on the address of the house.&lt;/p&gt;

&lt;p&gt;They pass my address (&lt;code&gt;houseAddress&lt;/code&gt;) in to the &lt;code&gt;changeTenant&lt;/code&gt; function, which expects to be passed an address (&lt;code&gt;houseLocation&lt;/code&gt;) of the &lt;strong&gt;type&lt;/strong&gt; &lt;em&gt;address of a house&lt;/em&gt; (&lt;code&gt;*house&lt;/code&gt;); when we pass a function something of type &lt;code&gt;*&lt;/code&gt;, that function expects a description of that type, which in this instance is the address of the house.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;houseLocation&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;occupant&lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt;&lt;span class="n"&gt;newTenant&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;We want to change the values of the house, so we access the &lt;code&gt;value&lt;/code&gt; at the address we passed to the function (&lt;code&gt;bensHouse{occupant: "Ben"}&lt;/code&gt;) and change the tenant to be the &lt;code&gt;newTenant&lt;/code&gt;, in this case, Paul.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt; go run main.go
The tenant is: {Ben} 
Changing tenant.....
The tenant is: {Paul} 
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



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