<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>Posts on Bytegod</title>
		<link>https://www.bytegod.com/posts/</link>
		<description>Recent content in Posts on Bytegod</description>
		<generator>Hugo -- gohugo.io</generator>
		<language>en-us</language>
		<copyright>This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.</copyright>
		<lastBuildDate>Tue, 25 May 2021 18:47:57 -0300</lastBuildDate>
		<atom:link href="https://www.bytegod.com/posts/index.xml" rel="self" type="application/rss+xml" />
		
		<item>
			<title>Dependency Injection and Testability in Ruby</title>
			<link>https://www.bytegod.com/posts/dependency-injection-and-testability-in-ruby/</link>
			<pubDate>Tue, 25 May 2021 18:47:57 -0300</pubDate>
			
			<guid>https://www.bytegod.com/posts/dependency-injection-and-testability-in-ruby/</guid>
			<description>This past week I was pairing with a teammate, and during the pair session, we asked many times, &amp;ldquo;How this part of the code could be more explicit and testable?&amp;rdquo;.
In this post, let&amp;rsquo;s explore a bit more of this idea. Keep in mind this is much more than testing. It&amp;rsquo;s about good design!
The title is a bit broad and would be hard to explain in detail and compare dependency injection (DI) and inversion of control (IoC) like in other languages/frameworks.</description>
			<content type="html"><![CDATA[<p>This past week I was pairing with a teammate, and during the pair session, we asked many times, &ldquo;How this part of the code could be more explicit and testable?&rdquo;.</p>

<p>In this post, let&rsquo;s explore a bit more of this idea. Keep in mind this is much more than testing. It&rsquo;s about good design!</p>

<p>The title is a bit broad and would be hard to explain in detail and compare dependency injection (DI) and inversion of control (IoC) like in other languages/frameworks.</p>

<p>Talking dependencies, I prefer to be explicit as I&rsquo;ve had experience working in codebases where things were instantiated all over the code, being hard to test and understand.</p>

<p>Let&rsquo;s begin with an example in Ruby. Think of a class, in this case, a <code>Person</code>. This class has a method that uses a third-party service that, given a place, returns geolocation data.</p>

<blockquote>
<p>Suppose I live in Sao Paulo/Brazil and I want to find its latitude and longitude.</p>
</blockquote>

<p>There are two different ways of achieving the same result for this example, so let&rsquo;s dive in.</p>

<p>First, it&rsquo;s possible to declare a dependency using a class method:</p>
<div class="highlight"><pre class="chroma"><code class="language-ruby" data-lang="ruby"><span class="k">class</span> <span class="nc">Person</span>
  <span class="k">def</span> <span class="nc">self</span><span class="o">.</span><span class="nf">geo_data</span><span class="p">(</span><span class="ss">geo_service</span><span class="p">:</span> <span class="no">GoogleMapsService</span><span class="o">.</span><span class="n">new</span><span class="p">,</span> <span class="ss">address</span><span class="p">:)</span>
    <span class="n">lat</span><span class="p">,</span> <span class="n">long</span> <span class="o">=</span> <span class="n">geo_service</span><span class="o">.</span><span class="n">find_by</span><span class="p">(</span><span class="n">address</span><span class="p">)</span>

    <span class="o">[</span><span class="n">lat</span><span class="p">,</span> <span class="n">long</span><span class="o">]</span>
  <span class="k">end</span>
<span class="k">end</span></code></pre></div>
<p>A class method receives its dependency and the <code>address</code> parameter, just that.
I usually try to think more in OOP terms in Ruby, so I must have good reasons to use class methods, but keep in mind they&rsquo;re helpful occasionally.</p>

<p>The other option that I find particularly interesting is  declaring the dependency explicitly via constructor using a named parameter with a default value:</p>
<div class="highlight"><pre class="chroma"><code class="language-ruby" data-lang="ruby"><span class="k">class</span> <span class="nc">Person</span>
  <span class="k">def</span> <span class="nf">initialize</span><span class="p">(</span><span class="ss">geo_service</span><span class="p">:</span> <span class="no">GoogleMapsService</span><span class="o">.</span><span class="n">new</span><span class="p">)</span>
    <span class="vi">@geo_service</span> <span class="o">=</span> <span class="n">geo_service</span>
  <span class="k">end</span>

  <span class="k">def</span> <span class="nf">geo_data</span><span class="p">(</span><span class="n">address</span><span class="p">)</span>
    <span class="n">lat</span><span class="p">,</span> <span class="n">long</span> <span class="o">=</span> <span class="vi">@geo_service</span><span class="o">.</span><span class="n">find_by</span><span class="p">(</span><span class="n">address</span><span class="p">)</span>

    <span class="o">[</span><span class="n">lat</span><span class="p">,</span> <span class="n">long</span><span class="o">]</span>
  <span class="k">end</span>
<span class="k">end</span>

<span class="n">person</span> <span class="o">=</span> <span class="no">Person</span><span class="o">.</span><span class="n">new</span>
<span class="n">geo_data</span> <span class="o">=</span> <span class="n">person</span><span class="o">.</span><span class="n">geo_data</span><span class="p">(</span><span class="s1">&#39;Avenida Paulista - Bela Vista, São Paulo - SP&#39;</span><span class="p">)</span>
<span class="nb">puts</span> <span class="n">geo_data</span> <span class="c1"># [-23.533773, -23.533773]</span></code></pre></div>
<p>Both choices are valid, and depending on how the service is used, favor one or another.
It&rsquo;s a matter of style that your codebase is very likely already using, so try to stick with it.</p>

<p>In my opinion, now the code has a better <em>explicit</em> design. By looking at the constructor, we can see its dependencies.</p>

<p>Good, but let&rsquo;s try to look at how it can make our tests more <em>testable</em> now. As you can imagine, calling an external service on your tests can make it slower and error-prone, like in the example where we need to invoke <code>@geo_service.find_by</code>. Before we see the alternative, notice that it&rsquo;s possible to use the always interesting <a href="https://github.com/vcr/vcr">VCR</a> gem for this, but not always needed.</p>

<p>We usually want our tests leaner and faster, so let&rsquo;s implement the <code>FakeMapsService</code> that could replace <code>GoogleMapsService</code>:</p>
<div class="highlight"><pre class="chroma"><code class="language-ruby" data-lang="ruby"><span class="k">class</span> <span class="nc">FakeMapsService</span>
  <span class="k">def</span> <span class="nf">find_by</span><span class="p">(</span><span class="n">address</span><span class="p">)</span>
    <span class="c1"># Notice that it has the same signature and return type as the real service method</span>
    <span class="o">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="o">]</span>
  <span class="k">end</span>
<span class="k">end</span>

<span class="n">person</span> <span class="o">=</span> <span class="no">Person</span><span class="o">.</span><span class="n">new</span><span class="p">(</span><span class="ss">geo_service</span><span class="p">:</span> <span class="no">FakeMapsService</span><span class="o">.</span><span class="n">new</span><span class="p">)</span>
<span class="n">geo_data</span> <span class="o">=</span> <span class="n">person</span><span class="o">.</span><span class="n">geo_data</span><span class="p">(</span><span class="s1">&#39;Avenida Paulista - Bela Vista, São Paulo - SP&#39;</span><span class="p">)</span>
<span class="nb">puts</span> <span class="n">geo_data</span> <span class="c1"># [1, 2]</span></code></pre></div>
<p>It&rsquo;s a class that respects the same contract as the real service, having an instance method <code>find_by(address)</code> that returns the same array containing latitude and longitude.
Even though a contrived example, <code>FakeMapsService</code> makes it easier to test now, avoiding the whole <em>mockery</em> we get used to:</p>
<div class="highlight"><pre class="chroma"><code class="language-ruby" data-lang="ruby"><span class="nb">require</span> <span class="s1">&#39;test/unit&#39;</span>
<span class="nb">require</span> <span class="s1">&#39;test/unit/assertions&#39;</span>
<span class="n">require_relative</span> <span class="s1">&#39;./person&#39;</span>

<span class="k">class</span> <span class="nc">PersonTest</span> <span class="o">&lt;</span> <span class="no">Test</span><span class="o">::</span><span class="no">Unit</span><span class="o">::</span><span class="no">TestCase</span>
  <span class="k">def</span> <span class="nf">test_geo_data</span>
    <span class="c1"># When creating our scenario, we change the real service for the fake one</span>
    <span class="n">person</span> <span class="o">=</span> <span class="no">Person</span><span class="o">.</span><span class="n">new</span><span class="p">(</span><span class="ss">geo_service</span><span class="p">:</span> <span class="no">FakeMapsService</span><span class="o">.</span><span class="n">new</span><span class="p">)</span>
    <span class="n">assert_equal</span> <span class="n">person</span><span class="o">.</span><span class="n">geo_data</span><span class="p">(</span><span class="s1">&#39;Wonderland, Nowhere&#39;</span><span class="p">),</span> <span class="o">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="o">]</span>
  <span class="k">end</span>
<span class="k">end</span></code></pre></div>
<p>So, that&rsquo;s it for now. It&rsquo;s a simple yet powerful idea that I&rsquo;ve used many times in Ruby and also Go!
In the next post, I&rsquo;ll cover a different example in Go about using the same approach for another problem.</p>

<p>I hope you enjoyed it, and thanks for reading!</p>
]]></content>
		</item>
		
		<item>
			<title>On Discussing Programming Languages</title>
			<link>https://www.bytegod.com/posts/on-discussing-programming-languages/</link>
			<pubDate>Mon, 21 Dec 2020 10:35:02 -0300</pubDate>
			
			<guid>https://www.bytegod.com/posts/on-discussing-programming-languages/</guid>
			<description>To discuss programming languages is generally noisy among us, technologists. We&amp;rsquo;re a different kind (for the good, for the bad), generally very opinionated.
The opinions change, also the perspectives and the experience, but the discussion was and always will be present.
In this post, I hope to bring light to the discussion. Don&amp;rsquo;t expect easy answers. I will ask much more than pretend I know the answers.
I use language and programming language interchangeably.</description>
			<content type="html"><![CDATA[

<p>To discuss programming languages is generally noisy among us, technologists. We&rsquo;re a different kind (for the good, for the bad), generally very opinionated.</p>

<p>The opinions change, also the perspectives and the experience, but the discussion was and always will be present.</p>

<p>In this post, I hope to bring light to the discussion. Don&rsquo;t expect easy answers. I will ask much more than pretend I know the answers.</p>

<p>I use <strong>language</strong> and <strong>programming language</strong> interchangeably.</p>

<p>We have to think!</p>

<h2 id="overview">Overview</h2>

<ul>
<li><a href="#your-mileage-may-vary">Your mileage may vary</a></li>
<li><a href="#behind-the-choices">Behind the choices</a>

<ul>
<li><a href="#high-invested">High invested</a></li>
<li><a href="#why-so-many-options">Why so many options</a></li>
<li><a href="#ecossystem">Ecossystem</a></li>
<li><a href="#hard-to-measure-aspects">Hard to measure aspects</a></li>
<li><a href="#productivity">Productivity</a></li>
<li><a href="#simple-vs-easy">Simple vs Easy</a></li>
</ul></li>
<li><a href="#wrapping-up">Wrapping up</a></li>
</ul>

<h2 id="your-mileage-may-vary">Your mileage may vary</h2>

<p>When we start developing it&rsquo;s relatively common to learn programming languages from the C family. Those are the languages that have a characteristic <code>if</code>, followed by <code>{}</code> and code in between. They usually have strong typing and good performance.</p>

<p>For example, a C program that checks if a number is even or odd (harvested from Internet):</p>
<div class="highlight"><pre class="chroma"><code class="language-c" data-lang="c"><span class="cp">#include</span><span class="cpf">&lt;stdio.h&gt;</span><span class="cp">
</span><span class="cp"></span><span class="kt">int</span> <span class="nf">main</span><span class="p">()</span>
<span class="p">{</span>
   <span class="c1">// This variable is to store the input number
</span><span class="c1"></span>   <span class="kt">int</span> <span class="n">num</span><span class="p">;</span>

   <span class="n">printf</span><span class="p">(</span><span class="s">&#34;Enter an integer: &#34;</span><span class="p">);</span>
   <span class="n">scanf</span><span class="p">(</span><span class="s">&#34;%d&#34;</span><span class="p">,</span><span class="o">&amp;</span><span class="n">num</span><span class="p">);</span>

   <span class="c1">// Modulus (%) returns remainder
</span><span class="c1"></span>   <span class="k">if</span> <span class="p">(</span> <span class="n">num</span><span class="o">%</span><span class="mi">2</span> <span class="o">==</span> <span class="mi">0</span> <span class="p">)</span>
      <span class="n">printf</span><span class="p">(</span><span class="s">&#34;%d is an even number&#34;</span><span class="p">,</span> <span class="n">num</span><span class="p">);</span>
   <span class="k">else</span>
      <span class="n">printf</span><span class="p">(</span><span class="s">&#34;%d is an odd number&#34;</span><span class="p">,</span> <span class="n">num</span><span class="p">);</span>

   <span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span></code></pre></div>
<p>After 1 or 2 years of writing code in the same language, it seems to be the only option.</p>

<p>You may have started from a different family of languages, that&rsquo;s not the point though.</p>

<p>Before learning C/C++ at college I had the opportunity to learn Clipper, Pascal, Visual Basic, and Delphi. Those were the first languages I learned that helped form a critical sense over it, each one with its <em>pros</em> and <em>cons.</em></p>

<p>The lesson here is: every programming language brings together someone else&rsquo;s experience.</p>

<h2 id="behind-the-choices">Behind the choices</h2>

<p>Unfortunately, it&rsquo;s common to ignore an important aspect of our choices:</p>

<ul>
<li>What is the motivation for creating a new programming language or tool?</li>
<li>Who created it?</li>
<li>What&rsquo;s the creator&rsquo;s background?</li>
</ul>

<p>You may not need to know it, but if you&rsquo;re the person responsible for deciding it, you better go look for it. This is probably the research which is gonna give you an interesting background. It&rsquo;s a good exercise that I recommend. The history behind the choices used to be fascinating!</p>

<p>Try to reflect on the following aspects:</p>

<ul>
<li>Was the language created in the &lsquo;60s? The &lsquo;70s?</li>
<li>If it&rsquo;s older, what was the hardware?</li>
<li>What did the language&rsquo;s creator choose to add and to remove from the design?</li>
</ul>

<p>As I promised, there are a lot of questions. Those are important inquiries you&rsquo;ll have to think about when you decide to create your language.</p>

<p>Let&rsquo;s suppose it&rsquo;s your time. You could ask yourself:</p>

<ul>
<li>Should my language be multi-paradigm or not? Functional, logic, imperative?</li>
<li>Compiled or interpreted?</li>
<li>Should I run on a Virtual Machine?</li>
<li>What about the type system&hellip;</li>
<li>Concurrency and parallelism</li>
<li>Do I have hardware limitations? Multiplatform?</li>
<li>Should I optimize for&hellip;</li>
<li>Should the compiler generate an intermediate language&hellip;</li>
</ul>

<p>It&rsquo;s your choices the same way someone has to think when creating the language you&rsquo;re using today. Every question leads to another one and has its consequences.</p>

<p>When I started I&rsquo;d never ask these questions. There&rsquo;re things I had no idea I didn&rsquo;t know. My baggage came through the years by exploring by using programming languages as a tool, exploring their usabilities and differences.</p>

<h3 id="high-invested">High invested</h3>

<p>For every choice, there&rsquo;s a level of investment of time and sometimes money. It doesn&rsquo;t matter if you&rsquo;re self-learned or not, you at least spent time learning it.</p>

<p>Let&rsquo;s suppose a new programming language is fresh over the web. As people are learning, other people are experimenting with their job, making it bigger, one step at a time. New books start being written, the publishers go look for them as the interest grows.</p>

<p>Naturally, you&rsquo;re inclined to appreciate it, you&rsquo;re growing together. Now, you can change jobs, apply your knowledge, and receive money for that.</p>

<p>New conferences appear then you can travel. The new language in the block shines, leverages your career, people ask for your help and you&rsquo;re seen as a reference.</p>

<p>There&rsquo;s a big factor that motivates these choices. For every investment, you naturally build a bias towards it.</p>

<p>Biases exist in different areas. Another example is when you buy a product and you&rsquo;re temporarily blind. You can&rsquo;t think of missing characteristics or points of failures, <strong>you&rsquo;re biased</strong>!</p>

<p>You&rsquo;re not ready to listen to your friend say:</p>

<blockquote>
<p>Wow, that&rsquo;s too expensive! Product A is much better in terms of&hellip;&rdquo;</p>
</blockquote>

<p>Good, one more step on establishing our feet on the ground!</p>

<h3 id="why-so-many-options">Why so many options?</h3>

<p>Programming languages can be classified into two larger groups: general-purpose or domain-specific.</p>

<p>For general-purpose languages, it tends to be more complicated. It&rsquo;s not always possible to add new features that were not thought <em>by-design</em>. Simply add a new feature might look foreign, out of context. We use to say it&rsquo;s not <em>idiomatic</em>.</p>

<p>Let&rsquo;s reflect on a few examples:</p>

<p>The Ruby language after +25 years decided that the language needed to adapt to modern hardware to stay relevant in terms of concurrency and parallelism. Wow! At least to me, that doesn&rsquo;t look pretty simple.</p>

<p>How to think this change for a language that, until then, hadn&rsquo;t this as a priority? We could say it&rsquo;s a matter of OCP (Open-Closed Principle), but it&rsquo;s <em>far harder</em> for programming languages than for applications.</p>

<p>To break or not break compatibility? Should we create primitives based on <em>keywords</em> or think in terms of a different abstraction? The designers have to think in the lifetime of the language, community, and its use from here on. What a huge effort is required!</p>

<p>Java itself, that year after has been changing. It&rsquo;s been a few releases since you can write Java code on a REPL too! JShell gives that flexibility tool existent for years on interpreted languages. In terms of functional programming, Java&rsquo;s brought too many options now.</p>

<p>I have no empirical reference, but I think Kotlin made Java open its eyes for evolution.</p>

<p>Go, after years of criticism and a divided community over <em>generics</em>, have finally materialized it for the next versions. Draft after draft, the designers have moved to a common goal with the help of the community.</p>

<p>Nothing is static. It&rsquo;s always time to adapt and move forward. Everyone learns. The tool of today might not be great for a problem of tomorrow.</p>

<h3 id="ecossystem">Ecossystem</h3>

<p>A language gains relevance, mainly in terms of industry, if there&rsquo;re libraries, tools, and things happening around. It&rsquo;s innate that, as humans, we need innovation. We need to see things evolving and vibrant.</p>

<p>If it grows too much, is natural that more code is produced (good and bad). The language&rsquo;s <em>affordance</em> naturally brings curious people. Nothing wrong with dummy libraries, code for the sake of code. That job of curation, to harvest repos and extract meaning is essential.</p>

<p>One more time, I don&rsquo;t have a point to prove this. It&rsquo;s something backed by my own experience.</p>

<h3 id="hard-to-measure-aspects">Hard to measure aspects</h3>

<p>I decided to write this post after reading a lot of discussions about it. The good, the bad, the evil. We, the people.</p>

<p>We&rsquo;re hooked by:</p>

<blockquote>
<p>My code is elegant</p>

<p>My code is beautiful</p>

<p>I prefer&hellip;</p>
</blockquote>

<p>It&rsquo;s authentic to assume:</p>

<blockquote>
<p>I&rsquo;ve adopted the language X because it looks different. It&rsquo;s the hype, I want to try it.</p>
</blockquote>

<p>The process of experimentation is quite common, but for more experienced developers, it goes differently. If you&rsquo;re being paid, working on a team, documenting your choices and decisions are very important.
Train people and make progress. If you can, give contributions back to the community.</p>

<p>I remember a video series from professor <a href="https://users.drew.edu/bburd/">Barry Burd</a>) about functional programming, where he talks about the famous <code>goto</code> keyword. It gained new forms but the levels of indirection still exist. Think in terms of <code>if</code>.</p>

<h3 id="productivity">Productivity</h3>

<p>This is a very broad term. I still don&rsquo;t know exactly what it means What does it mean to be productive? Is it when I create more LOC? If I create <em>keyboard bindings</em> to expand into code snippets, does it mean productivity? Your experience can have a total influence here.</p>

<p>You might be productive after years of writing code in the same language, mas is biased towards it. If you learn a new language, how long does it take to teach your brain the new semantics? What about the idiomatic way of writing it?</p>

<p>What if instead of productivity you mean <em>familiarity</em>? Naturally, the first encounter with a new programming language might feel weird. It happened to me when I first met Clojure. A different family of language that initially hurts, but helped me think differently.</p>

<p>See the Clojure code below that finds the greatest common divisor of a and b (harvested from the Internet):</p>
<div class="highlight"><pre class="chroma"><code class="language-clojure" data-lang="clojure"><span class="p">(</span><span class="kd">defn </span><span class="nv">gcd</span>
  <span class="s">&#34;(gcd a b) computes the greatest common divisor of a and b.&#34;</span>
  <span class="p">[</span><span class="nv">a</span> <span class="nv">b</span><span class="p">]</span>
  <span class="p">(</span><span class="k">if </span><span class="p">(</span><span class="nb">zero? </span><span class="nv">b</span><span class="p">)</span>
    <span class="nv">a</span>
    <span class="p">(</span><span class="nv">recur</span> <span class="nv">b</span> <span class="p">(</span><span class="nv">mod</span> <span class="nv">a</span> <span class="nv">b</span><span class="p">))))</span></code></pre></div>
<p>Nothing to compare here with the C code, isn&rsquo;t it?</p>

<h3 id="simple-vs-easy">Simple vs Easy</h3>

<p>This goes far.</p>

<blockquote>
<p>I write a lot of code in language X.</p>
</blockquote>

<p>What does it mean? If you write more code but the reading is easy, it&rsquo;s organized, what&rsquo;s the problem?</p>

<p>Do you write a lot of code because the language does not offer constructions and/or abstractions that make reuse possible? Notice that, everything is a <strong>tradeoff</strong>. The language may be raw and even though you write more code, the learning curve could be lower.</p>

<p>Every language allows us to write low cohesion code, with bad legibility. It&rsquo;s always possible to ignore the design purpose and deviate broadly from the ideas behind it. Non-idiomatic code is not an exclusivity of language X or Z. One more time you need to understand the choices and try to follow the best constructs.</p>

<p>I&rsquo;ve been there when I started learning Ruby. My code sounded like Java. It took me time to adapt and learn Ruby idioms. I read books on it and made progress. I read a lot of code. People helped me review my code and show the Ruby way of writing it.</p>

<p>Another aspect that looks foreign to me was the boom of <em>one-liners</em> methods — methods exclusively with one-single-line! It took me time to get used to those levels of indirections. Nowadays I use one-liners carefully and discuss their validity on code reviews.</p>

<p>Never buy an opinion based on a <code>Hello, world!</code> example. It&rsquo;s not a fair comparison that does not reflect reality. I&rsquo;m tired of seeing <em>contrived</em> examples comparisons trying to guide decisions.
It&rsquo;s much better to migrate a project of yours to a new language, try it and see if the model behind it is what you expect or not. Sometimes the exercise is worth doing just by doing. You might not need to prove anything and that&rsquo;s ok.</p>

<p>If you need examples and things to compare, <a href="http://rosettacode.org/wiki/Rosetta_Code">Rosetta Code</a> is better than a mere <code>hello_world.rb</code> vs <code>HelloWorld.java</code>.</p>

<h2 id="wrapping-up">Wrapping up</h2>

<p>Without further ado, let&rsquo;s sum up the idea. <strong>It all depends!</strong></p>

<p>Always I can, I try to look for papers and old books. So many ideas we think are new, comes from the &lsquo;70s, &lsquo;80s. It&rsquo;s nothing new, it&rsquo;s just possible to materialize it. New hardware, better usability, knowledge sharing.
As the idea of concurrency seems to be something new, but <a href="https://en.wikipedia.org/wiki/Communicating_sequential_processes">CSP</a> ideas were proposed by <a href="https://en.wikipedia.org/wiki/Tony_Hoare">Sir Tony Hoare</a> in the late &lsquo;70s.</p>

<p>Also, books, that I particularly really appreciate. Their format in which the authors needed to dig deeper before writing and exploring concepts. I <em>wholeheartedly</em> disagree with people that say that book is merely a theory. The books materialize the experience lived by someone else that you can reuse. It works like a shortcut in the great sense of the word. It opens doors.</p>

<p>Be <em>wary</em> of your choices.  Stay alert to no be the one-size-fits-all of programming languages. General-purpose languages make it possible and that&rsquo;s ok. If you need optimizations, go ahead with a specific purpose language, try them. No programming language can help with a problem you don&rsquo;t understand.</p>

<p>As I get older in terms of code, the more I realized it all depends. Maturity comes in great shape.</p>

<p>Try different flavors of languages, experiment with them, and make decisions.</p>

<p>Thanks for reading!</p>
]]></content>
		</item>
		
		<item>
			<title>Working Remotely for Almost a Year</title>
			<link>https://www.bytegod.com/posts/working-remotely-for-almost-a-year/</link>
			<pubDate>Sun, 08 Mar 2020 22:03:00 -0200</pubDate>
			
			<guid>https://www.bytegod.com/posts/working-remotely-for-almost-a-year/</guid>
			<description>This is not the freshest of the posts lately. Working remotely has been a known activity for years. I remember (circa 2006) my colleagues at IBM working from home. At the time, one of the main reasons was, that by staying at home with your ThinkPad had a huge potential for reducing costs given the high hiring growth they were passing through and consequently for the lack of physical spaces.</description>
			<content type="html"><![CDATA[

<p>This is not the <em>freshest</em> of the posts lately. Working remotely has been a known activity for years. I remember (<em>circa</em> 2006) my colleagues at IBM working from home. At the time, one of the main reasons was, that by staying at home with your ThinkPad had a huge potential for reducing costs given the high hiring growth they were passing through and consequently for the lack of physical spaces.</p>

<p>It&rsquo;s been years since <a href="https://basecamp.com/books/remote">Remote</a> and <a href="https://basecamp.com/books/rework">Rework</a> from <a href="https://basecamp.com">Basecamp</a> were released. Quite often, while discussing these books people complained about been so <em>extreme</em> that a lot of companies would never adapt to.</p>

<p>All the companies I&rsquo;d worked until 2018, remote was kind of uncommon. Communication worked like &ldquo;Tomorrow I&rsquo;ll work from home, ok?&rdquo;. It was a matter of reporting statuses, killing tasks and moving forward. But&hellip; not today. Things have changed in 2019 and I have almost entirely working from home. In this post I talk a bit about being constructive and contributing effectively with your company and teammates.</p>

<h2 id="how-things-appear-to-be-evolved">How things appear to be evolved</h2>

<p>You&rsquo;ll probably see through different lens, but let&rsquo;s try to list a few reasons things have changed. Remote work became <em>feasible</em> these days, if not the norm, for multiple reasons:</p>

<ul>
<li>Better Internet connections</li>
<li>Better computers</li>
<li>Better tools (wikis, chat, project management and video conference)</li>
<li>Talented people around the world</li>
<li>Work/life balance</li>
<li>A boom in renting prices</li>
<li>Crowded regions (more traffic, higher prices, etc)</li>
</ul>

<p>Today I live in the countryside of Brazil, having a 100 Mb/s fiber optical connection for R$89,00/month (~ US$18.00). It&rsquo;s fast, very fast and it rarely annoys me.</p>

<p>I work on a 13&rdquo; MacBook Pro 2017, 8GB RAM and 128GB of disk. It&rsquo;s not the high-end dream machine but works fine with Ruby most of the time. Almost nothing to complain, except Docker, that is a memory hog!</p>

<p>For the communication part, we keep things on Slack and the meetings occur on Hangouts Meet. These are good tools (not for privacy I suppose), but allows me to effectively communicate. I will talk more about the tools below, stay with me.</p>

<p>Among the reasons I decided to work remotely is the better balance between work and life. This might be a controversial point since a few people don&rsquo;t see this separation. Well, for me it&rsquo;s been good. I don&rsquo;t need an alarm or someone calling me &ldquo;It&rsquo;s time to leave!&rdquo;. My biological clock seems to be perfectly adjusted considering bed and wake time. No more commuting!</p>

<p>By working remotely I can have amazing teammates working with me no matter the location. They can simply do their best job. To be precise, code is something <em>virtual</em>, so the Internet is the main platform :P</p>

<p>The last point I suppose impacts me and people around the world is the cost of living. How many posts have you read about San Francisco, CA or New York, NY? Even here in Brazil, Sao Paulo has very expensive regions. It&rsquo;s curious how things got disturbed by the industry — the economics of the whole thing.</p>

<p>If you have higher salaries, the prices raise. Groceries, renting, healthcare, everything adjust accordingly. Believe it or not, it&rsquo;s very hard, maybe impossible, to change this dynamics.</p>

<h2 id="async-work">Async work</h2>

<p>It&rsquo;s very easy to engage in a conversation when you have a friend next to you. It happens synchronously and anyone can start it. In some rare occasions someone tells &ldquo;Could you please reach out in 2h?&rdquo;. When you&rsquo;re at the comfort of your home or wherever you choose  to work, things work differently.</p>

<p>Before working remotely I had an urge to immediately help, removing blocks and moving forward. I have to say it&rsquo;s different when you&rsquo;re at a distance. As most of the remote communications happen this way, you&rsquo;ll probably have a feeling of multitasking. You&rsquo;ll be effectively changing context the same way a single core processor does. Maybe using a time slice mode. Do something while others await.</p>

<p>While my code keeps waiting to be reviewed, I try to write down a better README or document situations my team might find.</p>

<p>In the beginning I had a sense of emergency to jot down something on Slack and keep an eye on it. Will the reactions come? Will people start a thread? This seemed so similar to a social network (is it?). After a few months I calmed down and forgot this feeling. I put things down and interested people would take turns interacting.</p>

<p>Particularly, everybody in my team is on the same timezone (UTC-03:00). If we had people working around the world, this would add a bigger weight on async communication. I have an idea of how this could work but I have no experience to write yet.</p>

<h2 id="written-communication">Written communication</h2>

<p>After a few months I noticed ideas vanishing. A lot things happened but it didn&rsquo;t stick. It was when I decided to read more about the topic. That was when I realized that, if you&rsquo;re working alone, you have to think collectively. If I write down my ideas, documentation or whatever, I&rsquo;m not only helping myself but the company as whole.</p>

<p>We&rsquo;ve been using Confluence for this even though I don&rsquo;t like it much. It feels slow. The features I like in Confluence is a change history, notifications and a comments section. It&rsquo;s not my dream tool but it&rsquo;s the default tool for documentation, so I embraced it. :P</p>

<p>We&rsquo;ve been using an effective approach for good communication. After the meetings we write down the date and what happened. This is a good way to address things and name people to address the issues/ideas. It works like a diary.</p>

<p>Before we advance to the next topics, I&rsquo;d like to explain how writing have helped me to express better the ideas.</p>

<p>I write anything, without revision. A crude text, bad punctuation and a lot of ideas. I invoke my writer soul, let things flow on my keyboard, then the async comes into play. I leave the text alone, maturing and when I my gut screams, I come back and invoke my editor soul.</p>

<p>You won&rsquo;t be perfect initially, but it&rsquo;s important to release the writer&rsquo;s hand, wander and come back later. Depending on the topic it&rsquo;s possible it will generate warm discussions. I believe it&rsquo;s where emojis work nice. The decrease the pressure, giving a ton of friendship and camaraderie.</p>

<h2 id="code-reviews">Code reviews</h2>

<p>I&rsquo;m a developer. What better way to communicate than using code reviews? We&rsquo;ve been using GitHub for this, so let&rsquo;s call it the right way — Pull Requests. You probably know, but GitHub is a service hosted on the web. It&rsquo;s like a bridge, it doesn&rsquo;t matter if you and your teammates are at the same space. You&rsquo;ll be using it or a similar tool.</p>

<p>Code reviews reaffirm the importance of written communication. Not in general terms, but in terms of code. By working remotely the first thing I considered was a PR template with the following:</p>

<ul>
<li>Describe the main idea behind it</li>
<li>You can create check lists</li>
<li>Describe the changes you&rsquo;re doing</li>
<li>If it&rsquo;s a breaking change, describe it</li>
<li>Describe steps to deploy, if needed</li>
</ul>

<p>GitHub have recently added very interesting features. You can mark as reviewed, select multiple lines for comment, change the code directly to the web interface and more. You can even open a <a href="https://github.blog/2019-02-14-introducing-draft-pull-requests/">draft PR</a> for appreciation.</p>

<p>The tone you define during the review is what makes it good or not. Don&rsquo;t forget to have empathy and always be constructive. It&rsquo;s a great way to learn and help people learn new techniques. If you want more details and best practices on code reviews, go check a <a href="https://www.bytegod.com/posts/what-is-a-code-review/">post</a>  I wrote a few months ago.</p>

<h3 id="github-notifications">GitHub notifications</h3>

<p>Nowadays, my team is responsible for 7 services. Ruby/Rails, Python and a Vue.js frontend. Can you image how many commits my teammates are pushing daily? I can&rsquo;t handle this through e-mail, so I try to keep sane by using <a href="https://github.com/notifications/beta">GitHub notifications</a>. It&rsquo;s still in beta but it already helped me by showing assigned issues, mentions, reviews requested and more.</p>

<h2 id="connections-people-and-internet">Connections (people and Internet)</h2>

<p>In the beginning, we tried to talk only during the meetings. It worked, but it lacked quality. As more people joined the team, it became crucial to see each other in video. Besides showing expression, it help us to establish a conversation tone. It&rsquo;s made the difference by bringing each other closer, to a more personal communication.</p>

<p>Not everything works smoothly as expected. The quality of connections varies for different reasons: a specific problem in the region or an overload in atypical days. When that happens, as a last resort we turn the video off. Not ideal, but it helps.</p>

<p>A downside I can feel sometimes is the human interaction. Being with your friends at work, having a lunch together, but is something I can overcome by traveling once in a while. If you really works in a distributed team, with different timezones, things may be worse.</p>

<h2 id="conclusion">Conclusion</h2>

<p>It&rsquo;s been a great experience working full time remote. I can focus a bit better without losing interactions. I still have the added benefit of not living far from the office. When things are more urgent or I need a personal approach, I can travel to meet people.</p>

<p>If you can learn two things from this post is:</p>

<ol>
<li>Take it easy (async is the way)</li>
<li>Write more</li>
</ol>

<p>I&rsquo;d like to thank my company <a href="https://cargox.com.br/">CargoX</a> for trusting me as one of the first 100% remote workers they hired. It&rsquo;s been amazing, effective and less stressful than I ever thought.</p>

<p>I hope you enjoyed reading this post as much as I did writing it! Enjoy :)</p>
]]></content>
		</item>
		
		<item>
			<title>Snitch and Open Source Collaboration</title>
			<link>https://www.bytegod.com/posts/snitch-and-open-source-collaboration/</link>
			<pubDate>Mon, 15 Jul 2019 21:41:55 -0300</pubDate>
			
			<guid>https://www.bytegod.com/posts/snitch-and-open-source-collaboration/</guid>
			<description>This is the story of a tool, released as open source.
Open source is something we use every day, even though giving nothing or just a few in return. I had already contributed with money. I helped individual developers, donated to Mozilla, Wikipedia and add-on creators. I even bought swags to help oh-my-zsh and more. I even paid US$80 for the great Sublime Text, a proprietary text editor in which people accept a pop up once in a while for the free version.</description>
			<content type="html"><![CDATA[

<p>This is the story of a tool, released as open source.</p>

<p>Open source is something we use every day, even though giving nothing or just a few in return. I had already contributed with money. I helped individual developers, donated to <a href="https://www.mozilla.org">Mozilla</a>, <a href="https://www.wikipedia.org">Wikipedia</a> and add-on creators. I even bought swags to help <a href="https://github.com/robbyrussell/oh-my-zsh">oh-my-zsh</a> and more. I even paid <code>US$80</code> for the great <a href="https://www.sublimetext.com">Sublime Text</a>, a <em>proprietary</em> text editor in which people accept a pop up once in a while for the free version.</p>

<p>You probably know the philosophy and all the benefits of open source, so I&rsquo;ll skip more of this. In this post, I want to focus on how chatting with a friend on a Friday evening, inspired by Linux philosophy of small tools and our love for <a href="https://golang.org">Go</a>, we created something interesting.</p>

<p>I&rsquo;d finished writing Ruby code and decided to explore a bit deeper Go&rsquo;s tooling and how to improve the workflow of my tests. I wanted faster feedbacks, but after exploring docs and more docs, I noticed Go had nothing similar. Back then, in 2014, when I was working with Ruby (I&rsquo;m back with Ruby!), I used <a href="https://github.com/guard/guard">Guard</a> to receive constant feedback of <em>passing</em> and <em>breaking</em> tests. Wow, why not in Go?!</p>

<h2 id="the-beginning">The beginning</h2>

<p>Before I got into analysis paralysis I called my friend <a href="https://github.com/victorprb">Victor</a> to tell him about this idea. He was just starting with Go and could give an <em>unbiased</em> feedback of how he felt writing tests. He liked the proposal, so I decided to try. I wrote a very minimal idea of how it should work. We chatted over Telegram to discuss a <em>usable</em> tool we could develop, with as few as possible code. You might call it a &ldquo;MVP&rdquo;. A few interactions and the following list emerged:</p>

<pre><code>- It should be focused on Go developers
- It should monitor *.go files
- It should be simple
- It should belong to the community
</code></pre>

<p>Small is better, so we embraced our initial philosophy of Linux small tools and stuck with it.
We relied on Go&rsquo;s <strong>file</strong>, <strong>filepath</strong> and <strong>os</strong> packages. Initially, anything beyond that we judged as a waste of time. At this point, the tool didn&rsquo;t have a name. It wasn&rsquo;t the right time to worry about it. Commit by commit we learned how this tool could help us. The first interaction was nothing but background notifications.</p>

<h2 id="how-it-works">How it works</h2>

<p>As we made the tool stable, before pushing to GitHub, we found a name: <code>snitch</code>.</p>

<p>Given a certain path, snitch watches Go files. If you don&rsquo;t pass the path param, it assumes the current directory. Defaults are great!
Particularly, snitch came to me by helping with TDD. You can write your tests or save my Go files and it tells you the current state of successes and failures.</p>

<p>As a good snitch person, it tells the good and bad news! The name sounds good and people on <a href="https://www.reddit.com/r/golang/comments/c71gk5/snitch_a_small_go_binary_that_watches_your_go/">Reddit</a> said it was the best name for a tool like that!</p>

<h2 id="why-go">Why Go?</h2>

<p>Snitch was born in the ecosystem. It was created for Go developers by Go developers. I won&rsquo;t praise Go again :P</p>

<h2 id="lessons-learned">Lessons learned</h2>

<p>This was that project that, with a few LOC, gave us a very interesting in return. With the help of GitHub, people interact, <del>love</del> star the project, fork it and open pull requests. It&rsquo;s beyond the code. To make it work, I have a few advices:</p>

<pre><code>- Start small
- Don't be so ambitious
- Iterate and improve
- Don't be afraid of criticism
- Write down your ideas
- Use &quot;what if...&quot; to play with new ideas
- Ask for honest feedback and go grab a coffee
</code></pre>

<h2 id="the-current-state">The current state</h2>

<p>The story be told, I think now it&rsquo;s time to see the code and try <a href="https://github.com/axcdnt/snitch">snitch</a>. You can collaborate on <a href="https://www.github.com">GitHub</a> by opening issues, suggesting features and showing love.</p>

<p>I believe snitch has reached a <em>stable</em> state with interesting features. We love beautiful code, but there&rsquo;s always room for improvements. The most recent PR added a colorized terminal output. I loved it and it was easy to write with the help of <a href="https://github.com/fatih/color">color</a> package. I must say that Go enabled us to write clear and legible code very fast!</p>

<h3 id="nerd-stats">Nerd stats</h3>

<p>The repo has no more than 310 LOCs today, including tests:</p>

<pre><code>find . -name '*.go' | xargs wc -l
      61 ./platform/notifier.go
      52 ./parser/result_test.go
      20 ./parser/result.go
     177 ./main.go
     310 total
</code></pre>

<p>I&rsquo;d like to thank people on Telegram, GitHub and Victor for the code and support!</p>

<p>Thanks for reading!</p>
]]></content>
		</item>
		
		<item>
			<title>What is a Code Review?</title>
			<link>https://www.bytegod.com/posts/what-is-a-code-review/</link>
			<pubDate>Sat, 05 Jan 2019 13:37:09 -0200</pubDate>
			
			<guid>https://www.bytegod.com/posts/what-is-a-code-review/</guid>
			<description>In this post, I&amp;rsquo;m gonna introduce a very important practice in Software Engineering: code reviews.
Overview  What is a code review? Why General aspects Best practices  As the author As a reviewer  Biases Conclusion  What is a code review? If you are a developer, no matter how experienced you are, you&amp;rsquo;ll make mistakes. Code reviews are a practice in Software Engineering that in general, help developers to find defects, design problems, assure best practices compliance and apply knowledge transfer before delivering code.</description>
			<content type="html"><![CDATA[

<p>In this post, I&rsquo;m gonna introduce a very important practice in Software Engineering: code reviews.</p>

<h2 id="overview">Overview</h2>

<ul>
<li>What is a code review?</li>
<li>Why</li>
<li>General aspects</li>
<li>Best practices

<ul>
<li>As the author</li>
<li>As a reviewer</li>
</ul></li>
<li>Biases</li>
<li>Conclusion</li>
</ul>

<h1 id="what-is-a-code-review">What is a code review?</h1>

<p>If you are a developer, no matter how experienced you are, you&rsquo;ll make mistakes. Code reviews are a practice in Software Engineering that in general, help developers to find <em>defects</em>, <em>design problems</em>, assure <em>best practices compliance</em> and apply <em>knowledge transfer</em> before delivering code.</p>

<p>I really enjoy code review sessions, so I always try to bring this practice to every company I work for. It&rsquo;s great for learning new things, share opinions and give great feedback!</p>

<h2 id="why">Why</h2>

<p>We want the best code as possible to be delivered. Code that can grow organically, following the good principles of Software Engineering.</p>

<ul>
<li><p>Defects: During a code review, we can find if something was misunderstood, even communication issues.</p></li>

<li><p>Design problems: it&rsquo;s quite common to think in solutions and forget dark parts of the problem. This is a good time to find design issues that, maybe not now, but in the near future can cause problems. This is quite common with non-functional requirements.</p></li>

<li><p>Best practices: each programming language has its <em>quirks</em>, so we look for adherence to the idiomatic code. Static analysis tool can help here.</p></li>

<li><p>Knowledge transfer: everybody learns. Senior or junior, we make mistakes and write beautiful code!</p></li>
</ul>

<h2 id="general-aspects">General aspects</h2>

<p>Leading a code review session requires a few things to keep in mind in order to avoid biases and preconceived ideas. A session usually takes many minutes of interactions through code acceptance.</p>

<p>Code reviews are <em>independent</em> of programming languages. Scripts, build and automation code can also be reviewed. Recently, I also recommended my peers to review infrastructure code, an area whose is known to neglect code before the DevOps culture appeared. Things are changing and for the best!</p>

<p>The code review is only possible because of the <a href="https://en.wikipedia.org/wiki/Version_control">VCS</a> software like  <a href="https://git-scm.com/">git</a>. There are services that integrate with git and make it possible to have a centralized place, where you and your team members can establish a conversation and give feedback. Services like <a href="https://gitlab.com/">GitLab</a>, <a href="https://github.com">GitHub</a> and <a href="https://bitbucket.org/">BitBucket</a> are examples of that.</p>

<h3 id="how-it-happens">How it happens</h3>

<p>This is a way to review code, with your team you should define what is best and adapt if something doesn&rsquo;t work.</p>

<p>Developers are responsible for frequently committing their code and when it&rsquo;s ready or even when they feel feedback is needed, it is a good time to start a code review. If you&rsquo;re on GitLab, reviews are called <strong>Merge Request</strong>. If it&rsquo;s GitHub - <strong>Pull Request</strong>.</p>

<p>There are different ways of starting a review according to the git flow of your choice. My team currently works with a <em>master</em> branch - a known place for stable code. In this case, everything we develop must pass the review before being added back to master.</p>

<p>After three days, you finished your so expected feature. Tests are all green, static analysis ran, no issues found. You&rsquo;re ready to start a review before finally shipping your code.</p>

<p>It&rsquo;s time to choose one or more members of your team to subscribe to the review, give suggestions and receive notifications of interactions.</p>

<h2 id="best-practices">Best practices</h2>

<p>No matter if you&rsquo;re opening a review or you&rsquo;ll act as a reviewer, empathy must guide both of them. Respect, help and contribute with your peers. It&rsquo;s a <del>rule</del> good manner.</p>

<h3 id="as-the-author">As the author</h3>

<p>Having your code reviewed demands empathy overall. Don&rsquo;t try to look so smart.
Let&rsquo;s see a few practices that guide your good code:</p>

<ul>
<li><p>Small commits: try to reduce the number of commits. Git <a href="https://git-scm.com/book/en/v2/Git-Tools-Rewriting-History">squash</a> may help!</p></li>

<li><p>Descriptive review: write a near-perfect title for it, with a detailed description (Is it a bug? A feature? Dark details, etc)</p></li>

<li><p>Scope: keep the scope of your changes limited. Your peers will thank you.</p></li>

<li><p>Explain your decisions: if there&rsquo;s something a bit more complicated, algorithms choice, explain it.</p></li>

<li><p>Choose the reviewers: sometimes, people are very busy, so choose wisely who can collaborate more with your review. Be by subject expertise or availability, don&rsquo;t choose just your friends.</p></li>

<li><p>Don&rsquo;t take it too personally. Don&rsquo;t be offended you received constructive critics.</p></li>
</ul>

<h3 id="as-a-reviewer">As a reviewer</h3>

<p>There are different things to look for while reviewing. I really enjoy the design aspects of the code. If we are in review session of Go code, I&rsquo;ll look for the lack of <strong>idiomatic</strong> Go. Now, let&rsquo;s see how to lead the review by the reviewer&rsquo;s perspective:</p>

<ul>
<li><p>Purpose: does the author followed the best practices, tested and write good documentation? Does this review follow the guidelines your team established?</p></li>

<li><p>Ask: this is very important. If you see code that&rsquo;s is confusing, hard to understand, non-idiomatic, please ask! You&rsquo;re helping not only yourself but your coworker.</p></li>

<li><p>Non-function requirements: if there&rsquo;s something that smells bad, ask! Let&rsquo;s suppose you found a piece of good that could cause bad performance, leave a question. You may not see something your co-worker wrote or it&rsquo;s justified.</p></li>

<li><p>Look for unnecessary code: developers enjoy writing code, even when it&rsquo;s not necessary. If you found something a lib solves better or it&rsquo;s faulty, ask, suggest.</p></li>

<li><p>Is this code extensible? If not, give ideas on how to make it extensible.</p></li>

<li><p>Is this code clear enough for all the team members understand?</p></li>

<li><p>Does this code leave a future change? The infamous technical debts. If yes, create an issue and add a due date to it.</p></li>

<li><p>Are the unit/integration tests given the same care as the code itself? Test code is code.</p></li>

<li><p>Security: it goes deeper, look for potential security breaches and raise questions.</p></li>

<li><p>For bigger reviews (too many files, classes/methods, functions, etc), I highly recommend to checkout the branch locally and use your editor/ide to navigate the code. If you use a static analysis tool, it&rsquo;ll help by warning about problems.</p></li>
</ul>

<h2 id="biases">Biases</h2>

<p>I&rsquo;ve worked in places where people were code review <em>fanatics</em>. It was bad. No good conversations, just nitty pick details and a lot of egos. Please, don&rsquo;t do that! I believe in teaching, educating people and feedback is priceless in this case. Why, instead of pointing your finger, don&rsquo;t you show <em>how</em> and <em>why</em> your suggestions would be better?</p>

<h2 id="conclusion">Conclusion</h2>

<p>Code review is an essential practice for professionals. It dramatically improves the quality of the code, decreases the number of bugs and shares knowledge. <strong>The adoption of reviewing code is part of a transition from Software Development to Software Engineering.</strong> It&rsquo;s when you learn to work on a team, divide work and iterate into small steps to delivery well-engineered code.</p>

<p>It&rsquo;s time well spent. Apparently, it isn&rsquo;t generating value, but if you look closer, all your users want is software that works. It&rsquo;s only possible with good practices of real engineering.</p>

<p>Thanks for reading!</p>
]]></content>
		</item>
		
		<item>
			<title>An Intro to Go</title>
			<link>https://www.bytegod.com/posts/an-intro-to-go/</link>
			<pubDate>Tue, 01 Jan 2019 22:05:00 -0200</pubDate>
			
			<guid>https://www.bytegod.com/posts/an-intro-to-go/</guid>
			<description>Overview  What is Go? Characteristics Syntax and use-cases The learning path  Don&amp;rsquo;t expect that Go will save the world, but I must say it&amp;rsquo;s a pleasure to work with!
What is Go? Go is programming language born inside Google, created aiming software engineers and looking to solve problems Google faced at that time (conceived in 2007 and officially released in 2009). The main design goals for the language were:</description>
			<content type="html"><![CDATA[

<h2 id="overview">Overview</h2>

<ul>
<li>What is Go?</li>
<li>Characteristics</li>
<li>Syntax and use-cases</li>
<li>The learning path</li>
</ul>

<p>Don&rsquo;t expect that Go will save the world, but I must say it&rsquo;s a pleasure to work with!</p>

<h2 id="what-is-go">What is Go?</h2>

<p>Go is programming language born inside Google, created aiming software engineers and looking to solve problems Google faced at that time (conceived in 2007 and officially released in 2009). The main design goals for the language were:</p>

<ul>
<li>Productivity</li>
<li>Multicore processors</li>
<li>Networking</li>
<li>Large codebases</li>
</ul>

<p>If you&rsquo;re gonna look for more resources about Go, you better look for Golang/golang. I consider the word &ldquo;Go&rdquo; not very <em>searchable</em>. As you may know, naming things is one of the hardest things in Computer Science.</p>

<p>Go creators (Robert Griesemer, Rob Pike and Ken Thompson) are a mix of <em>academia</em> and <em>industry</em>. They looked for performance and low-level details without neglecting ease of use and bootstrapping.</p>

<h2 id="characteristics">Characteristics</h2>

<p>Among the many features the language has, those who catch my eyes are:</p>

<ul>
<li>Static typing but a bit relaxed</li>
<li>Concurrency</li>
<li>Productivity</li>
<li>Web servers</li>
<li>Multi-platform binary</li>
<li>Great tools: test, coverage and performance</li>
<li>Code formatter</li>
<li>Great documentation</li>
<li>Amazing for CLI apps and APIs (my opinion of course!)</li>
</ul>

<h2 id="syntax-and-use-cases">Syntax and use-cases</h2>

<p>Go is in many aspects, similar to C, but also different of C. It favors <em>brevity</em>, <em>simplicity</em> and <em>safety</em>.</p>

<p>I consider very important to learn new paradigms and programming languages. To look at a problem and see how it can be solved with the proper technology is something quite interesting. There are a lot of specialized things, created to solve very specific problems and we must know that!</p>

<p>With Go I find it particularly very useful for distributed systems. The language was created with multicores in mind, so it&rsquo;s a feature you already have when choosing it.</p>

<p>In 2017 a coworker was starting a new project at my previous company. It was a CI/CD container platform. One day he came to me and asked for an opinion: &ldquo;What do you think of Go?&rdquo; He&rsquo;d started to write it in Python and was happy with the result, but he&rsquo;d like to try something new. The first aspects I came to mention was - how the language is very readable and explicit, two things I judge essential for big codebases and complex software.</p>

<p>As we were using Docker and they provide, besides Python, a Go SDK, we decided to try it. Let&rsquo;s see a bit of code to illustrate the syntax:</p>

<div class="highlight"><pre class="chroma"><code class="language-go" data-lang="go"><span class="ln"> 1</span><span class="kn">package</span> <span class="nx">main</span>
<span class="ln"> 2</span>
<span class="ln"> 3</span><span class="kn">import</span> <span class="p">(</span>
<span class="ln"> 4</span>	<span class="s">&#34;fmt&#34;</span>
<span class="ln"> 5</span><span class="p">)</span>
<span class="ln"> 6</span>
<span class="ln"> 7</span><span class="kd">func</span> <span class="nf">main</span><span class="p">()</span> <span class="p">{</span>
<span class="ln"> 8</span>	<span class="nx">hoursInADay</span> <span class="o">:=</span> <span class="mi">24</span>
<span class="ln"> 9</span>	<span class="nx">fmt</span><span class="p">.</span><span class="nf">Printf</span><span class="p">(</span><span class="s">&#34;A day has %d hours&#34;</span><span class="p">,</span> <span class="nx">hoursInADay</span><span class="p">)</span>
<span class="ln">10</span><span class="p">}</span></code></pre></div>

<p>Notice that, every Go code lives inside a package. A package is nothing more than a dir inside your project. If your code is <em>executable</em>, it necessarily must have a <code>main</code> function in the <code>main</code> package. This function works as the starting point of your application.</p>

<p>Every function call in Go is preceded by the package: <code>fmt.Printf(...)</code>. <code>fmt</code> is the package and <code>Printf(...)</code> an exported function from this package. Functions beginning with an uppercase letter are is visible to other packages, while functions beginning with a lowercase letter are visible only inside its own package.</p>

<p>The support for tests is really nice too. No frameworks, libs or whatever. The language has the test tools built-in. Let&rsquo;s see an example:</p>

<div class="highlight"><pre class="chroma"><code class="language-go" data-lang="go"><span class="ln"> 1</span><span class="kn">package</span> <span class="nx">main</span>
<span class="ln"> 2</span>
<span class="ln"> 3</span><span class="kn">import</span> <span class="s">&#34;testing&#34;</span>
<span class="ln"> 4</span>
<span class="ln"> 5</span><span class="kd">func</span> <span class="nf">TestReverse</span><span class="p">(</span><span class="nx">t</span> <span class="o">*</span><span class="nx">testing</span><span class="p">.</span><span class="nx">T</span><span class="p">)</span> <span class="p">{</span>
<span class="ln"> 6</span>	<span class="nx">tests</span> <span class="o">:=</span> <span class="p">[]</span><span class="kd">struct</span> <span class="p">{</span>
<span class="ln"> 7</span>		<span class="nx">in</span>  <span class="kt">string</span>
<span class="ln"> 8</span>		<span class="nx">out</span> <span class="kt">string</span>
<span class="ln"> 9</span>	<span class="p">}{</span>
<span class="ln">10</span>		<span class="p">{</span><span class="s">&#34;apple&#34;</span><span class="p">,</span> <span class="s">&#34;elppa&#34;</span><span class="p">},</span>
<span class="ln">11</span>		<span class="p">{</span><span class="s">&#34;banana&#34;</span><span class="p">,</span> <span class="s">&#34;ananab&#34;</span><span class="p">},</span>
<span class="ln">12</span>		<span class="p">{</span><span class="s">&#34;mango&#34;</span><span class="p">,</span> <span class="s">&#34;ognam&#34;</span><span class="p">},</span>
<span class="ln">13</span>	<span class="p">}</span>
<span class="ln">14</span>
<span class="ln">15</span>	<span class="k">for</span> <span class="nx">_</span><span class="p">,</span> <span class="nx">tt</span> <span class="o">:=</span> <span class="k">range</span> <span class="nx">tests</span> <span class="p">{</span>
<span class="ln">16</span>		<span class="nx">t</span><span class="p">.</span><span class="nf">Run</span><span class="p">(</span><span class="nx">tt</span><span class="p">.</span><span class="nx">in</span><span class="p">,</span> <span class="kd">func</span><span class="p">(</span><span class="nx">t</span> <span class="o">*</span><span class="nx">testing</span><span class="p">.</span><span class="nx">T</span><span class="p">)</span> <span class="p">{</span>
<span class="ln">17</span>			<span class="nx">str</span> <span class="o">:=</span> <span class="nf">Reverse</span><span class="p">(</span><span class="nx">tt</span><span class="p">.</span><span class="nx">in</span><span class="p">)</span>
<span class="ln">18</span>			<span class="k">if</span> <span class="nx">str</span> <span class="o">!=</span> <span class="nx">tt</span><span class="p">.</span><span class="nx">out</span> <span class="p">{</span>
<span class="ln">19</span>				<span class="nx">t</span><span class="p">.</span><span class="nf">Errorf</span><span class="p">(</span><span class="s">&#34;got %q, want %q&#34;</span><span class="p">,</span> <span class="nx">str</span><span class="p">,</span> <span class="nx">tt</span><span class="p">.</span><span class="nx">out</span><span class="p">)</span>
<span class="ln">20</span>			<span class="p">}</span>
<span class="ln">21</span>		<span class="p">})</span>
<span class="ln">22</span>	<span class="p">}</span>
<span class="ln">23</span><span class="p">}</span></code></pre></div>

<p>This test validates if a <code>string</code> is reversed. As it&rsquo;s a table test, we can pass multiple values of input and output and see if it works. Go also has a specific kind of test to validate performance, known as <em>benchmark</em> tests.</p>

<h2 id="the-learning-path">The learning path</h2>

<p>As the language is concise and its syntax is kind of familiar for people who&rsquo;ve learned programming languages or have been in a CS course, no big surprises.</p>

<p>I first started learning with <a href="https://tour.golang.org/welcome/1">A Tour of Go</a>. It covers all the features and better yet, with lots of exercises to practice. After that, I read <a href="https://www.amazon.com/Introducing-Go-Reliable-Scalable-Programs/dp/1491941952/ref=sr_1_1?s=books&amp;ie=UTF8&amp;qid=1546388617&amp;sr=1-1&amp;keywords=introducing+go">Introducing Go</a> and today I use <a href="https://www.amazon.com/Programming-Language-Addison-Wesley-Professional-Computing/dp/0134190440">The Bible</a> for reference. Both are great books and rest assured there are a lot of advanced books on the topic. I&rsquo;ll talk about them in future posts.</p>

<p>The best way to try Go is the <a href="https://play.golang.org/">Go Playground</a>. It&rsquo;s a REPL (read, eval, print and loop) on the web! No installation, no headaches, just code.</p>

<p>It&rsquo;s been almost 3 years since I started working and playing with Go and I must say that I really enjoy it.</p>

<p>Well, that&rsquo;s it. I hope you enjoy this overview and in the next post, I&rsquo;ll go deeper with code. Thanks for reading!</p>
]]></content>
		</item>
		
	</channel>
</rss>
