<?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>Forem: William Antonelli</title>
    <description>The latest articles on Forem by William Antonelli (@nanohard).</description>
    <link>https://forem.com/nanohard</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%2F143199%2F4df9d950-8548-47e7-bc37-a0a7cfe5ea3c.jpg</url>
      <title>Forem: William Antonelli</title>
      <link>https://forem.com/nanohard</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/nanohard"/>
    <language>en</language>
    <item>
      <title>go.mod replace: fallthrough</title>
      <dc:creator>William Antonelli</dc:creator>
      <pubDate>Sat, 08 Jun 2019 11:59:33 +0000</pubDate>
      <link>https://forem.com/nanohard/go-mod-replace-fallthrough-2k8p</link>
      <guid>https://forem.com/nanohard/go-mod-replace-fallthrough-2k8p</guid>
      <description>&lt;h3&gt;
  
  
  How do you use &lt;code&gt;replace&lt;/code&gt; in &lt;code&gt;go.mod&lt;/code&gt; when you want to replace a pkg that an imported pkg uses?
&lt;/h3&gt;

&lt;h2&gt;
  
  
  The Problem
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Project&lt;/strong&gt; uses &lt;strong&gt;Lib&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Lib&lt;/strong&gt; uses &lt;strong&gt;SubLib&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Project
  Lib
    SubLib
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You want to replace &lt;strong&gt;SubLib&lt;/strong&gt; with a local version that you're working on to see the result in &lt;strong&gt;Project&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Answer
&lt;/h2&gt;

&lt;p&gt;Open &lt;code&gt;go.mod&lt;/code&gt; in &lt;strong&gt;Project&lt;/strong&gt; to use the &lt;code&gt;replace&lt;/code&gt; directive.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// go.mod

require(
  github.com/example/lib
  // `lib` imports github.com/sublib/sublib
)

replace github.com/sublib/sublib =&amp;gt; /local/dir/sublib
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Profit!&lt;/p&gt;

&lt;p&gt;May my hours of suffering help another.&lt;/p&gt;

</description>
      <category>go</category>
      <category>programming</category>
    </item>
    <item>
      <title>When Files Are Better Than a DB</title>
      <dc:creator>William Antonelli</dc:creator>
      <pubDate>Wed, 29 May 2019 13:30:40 +0000</pubDate>
      <link>https://forem.com/nanohard/when-files-are-better-than-a-db-2pic</link>
      <guid>https://forem.com/nanohard/when-files-are-better-than-a-db-2pic</guid>
      <description>&lt;h2&gt;
  
  
  That's a lot of data!
&lt;/h2&gt;

&lt;p&gt;While creating a roguelike game in golang I got to the point of needing to save the objects. Naturally my first thought was to use a database, and of course I didn't want to use something heavy and external, but rather light and embeddable, so I chose &lt;a href="https://github.com/asdine/storm"&gt;storm&lt;/a&gt;, a toolkit for &lt;a href="https://github.com/etcd-io/bbolt"&gt;bbolt&lt;/a&gt;. bbolt is a key/value datastore that writes to disk. But when one Screen's worth of objects is a few hundred MB, and you have 240 Screens in the world, well... the query results tend to get mangled after saving just 2-3 Screens. I had very weird results wherein the last 12% to 40% of the results from one Screen query weren't being processed correctly. Combine this with the query taking a few seconds due to the DB easily growing by 300MB for each Screen added, and it becomes apparent that a different method is needed.&lt;/p&gt;

&lt;h2&gt;
  
  
  The world is flat!
&lt;/h2&gt;

&lt;p&gt;Enter the flat-file database. Instead of one giant datastore, I decided that each Screen would be a named folder, and inside there would be a separate file for each object. This yielded much better speeds for the program. For this method I used &lt;a href="https://github.com/nanobox-io/golang-scribble"&gt;scribble&lt;/a&gt;. This project uses JSON as the file structure, but I don't need the files to be human-readable so I modified it to use encoding/binary. There is a library that was created to be able to use encoding/binary as a drop-in replacement of encoding/json by implementing the Marshaler and Unmarshaler interfaces: &lt;a href="https://github.com/kelindar/binary"&gt;github.com/kelindar/binary&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;By using encoding/binary instead of encoding/json the file sizes are reduced and there's also a bit of a performance increase.&lt;/p&gt;

&lt;p&gt;Obviously I need to tune the program to not use so much space, but I like to test things under a high load to see how it performs, and in this case it paid off.&lt;/p&gt;

&lt;p&gt;My version of Scribble can be found here:&lt;br&gt;
&lt;a href="https://github.com/nanohard/scribble"&gt;https://github.com/nanohard/scribble&lt;/a&gt;&lt;/p&gt;

</description>
      <category>go</category>
      <category>database</category>
      <category>gamedev</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
