<?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: Kai</title>
    <description>The latest articles on DEV Community by Kai (@kaipmdh).</description>
    <link>https://dev.to/kaipmdh</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%2F420572%2F8c79f084-6e67-4e45-8023-d846b130de13.jpg</url>
      <title>DEV Community: Kai</title>
      <link>https://dev.to/kaipmdh</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/kaipmdh"/>
    <language>en</language>
    <item>
      <title>Getting Going with Go, Day 4</title>
      <dc:creator>Kai</dc:creator>
      <pubDate>Thu, 28 Jan 2021 20:28:01 +0000</pubDate>
      <link>https://dev.to/kaipmdh/getting-going-with-go-day-4-406h</link>
      <guid>https://dev.to/kaipmdh/getting-going-with-go-day-4-406h</guid>
      <description>&lt;p&gt;Today I thought I’d look into static typing of variables, as it’s a fundamental quality of Go as a language.&lt;/p&gt;

&lt;p&gt;So, in languages like Python, you could very easily do the following with variables:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"bc"&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;
&lt;span class="s"&gt;'bc'&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;
&lt;span class="mi"&gt;3&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In languages such as these, a variable is just a container for &lt;em&gt;stuff&lt;/em&gt;. You can change what stuff goes in mid-stream, dynamically changing the type of the variable.&lt;/p&gt;

&lt;p&gt;In comparison, Go is a statically typed language. You can either declare a variable explicitly with its type for use later (&lt;code&gt;var x int&lt;/code&gt; for integer) or inferred at creation time (&lt;code&gt;x := "hello"&lt;/code&gt; for a string containing “hello”) So of course I’m going to try the same exact hijinks as above:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-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;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;a&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="s"&gt;"bc"&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;Print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;3&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;Print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&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;Trying to build or &lt;code&gt;go run prog.go&lt;/code&gt; spits out an error message:&lt;br&gt;
&lt;code&gt;./prog.go:8:4: cannot use 3 (type untyped int) as type string in assignment&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Okay. But what happens if we try to dynamically reassign to the existing variable &lt;code&gt;a&lt;/code&gt;?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-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;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;a&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="s"&gt;"bc"&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;Print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="m"&gt;3&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;Print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&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;Unsurprisingly, we get the same error as before, but also a complaint about trying to assign a variable using the type-inferring &lt;code&gt;:=&lt;/code&gt; operator:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;./prog.go:8:4: no new variables on left side of :=
./prog.go:8:4: cannot use 3 (type untyped int) as type string in assignment
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;OK, so what if we redeclare the variable as a different type after we use it?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-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;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;a&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="s"&gt;"bc"&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;Print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;
    &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;3&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;Print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&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;No dice:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;./prog.go:8:6: a redeclared in this block
    previous declaration at ./prog.go:6:2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Just as an aside, what I do really like about the stack trace here is that it doesn’t just bomb out with “type mismatch” or whatever. It’s actually quite friendly - it tells us that on line 8, position 6 a redeclaration of a variable occurs, and even where it was originally declared.&lt;/p&gt;

&lt;h3&gt;
  
  
  But why all this hassle about typing? I just want to cram stuff into my variables
&lt;/h3&gt;

&lt;p&gt;The reason for static typing is, unsurprisingly, &lt;a href="https://hackernoon.com/i-finally-understand-static-vs-dynamic-typing-and-you-will-too-ad0c2bd0acc7"&gt;efficiency of execution&lt;/a&gt;. Because the program isn’t constantly checking the type of information in variables that it processes to see what it can do with them, it’s simply faster to run. This plays right into the fact that Go is a compiled language, so all of that checking and translation into machine code is done once at the compilation stage, not every single time the program is invoked. Efficiency!&lt;/p&gt;

&lt;p&gt;So, while it makes little sense to have your little script that you use to sift through information that you pass it on occasion written in Go, if you’re having something chomp on lots of data or be invoked lots of times, the efficiencies become clear.&lt;/p&gt;

&lt;p&gt;But there isn’t one type of programming paradigm that’s dominant at the expense of others. If all you have is a hammer, then everything looks like a nail. You’re going to need the right tool for the right job, and statically typed and compiled languages like Go are the right tools for particular jobs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting information out of variables
&lt;/h2&gt;

&lt;p&gt;Let's declare a few variables and use Go's syntax of printing information about them (&lt;code&gt;fmt.Printf()&lt;/code&gt;):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-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;var&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;DemoString&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Hello, world!"&lt;/span&gt;
    &lt;span class="n"&gt;Boolean&lt;/span&gt;    &lt;span class="kt"&gt;bool&lt;/span&gt;    &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;true&lt;/span&gt;
    &lt;span class="n"&gt;FloatingPt&lt;/span&gt; &lt;span class="kt"&gt;float32&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;1234.567&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;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;"DemoString is a variable of type: %T. It has the value of %v"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;DemoString&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;DemoString&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;"Boolean is a variable of type: %T. It has the value of %v"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Boolean&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Boolean&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;"FloatingPt is a variable of type: %T. It has the value of %v"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;FloatingPt&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;FloatingPt&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;This gets you:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;DemoString is a variable of type: string. It has the value of Hello, world!
Boolean is a variable of type: bool. It has the value of true
FloatingPt is a variable of type: float32. It has the value of 1234.567
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It's important to note here that you &lt;em&gt;cannot&lt;/em&gt; print the name of a basic declared variable in Go. As the human-readable names are discarded at compile time, you're left with just their values and types. That's why in the above example I had to manually put the name in to the string I was printing, and then get the value and type from the program itself. Also notice that the interpolation proceeds left to right with references at the end of the line, so for every interpolation you have to declare the variable to be used at the end of the expression.&lt;/p&gt;

&lt;h2&gt;
  
  
  References and further reading
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://tour.golang.org/basics/11"&gt;A Tour of Go - Basic Types&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://hackernoon.com/i-finally-understand-static-vs-dynamic-typing-and-you-will-too-ad0c2bd0acc7"&gt;I Finally Understand Static vs Dynamic Typing and You Will Too!&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Cover image: Photo by &lt;a href="https://unsplash.com/@mbaumi?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText"&gt;Mika Baumeister on Unsplash&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Tomorrow, who knows? It’s a Friday, so I might be doing this with a glass of wine…&lt;/p&gt;

</description>
      <category>go</category>
      <category>codenewbie</category>
      <category>100daysofcode</category>
    </item>
    <item>
      <title>Getting Going with Go, Day 3</title>
      <dc:creator>Kai</dc:creator>
      <pubDate>Wed, 27 Jan 2021 18:53:51 +0000</pubDate>
      <link>https://dev.to/kaipmdh/getting-going-with-go-day-3-3mof</link>
      <guid>https://dev.to/kaipmdh/getting-going-with-go-day-3-3mof</guid>
      <description>&lt;h2&gt;
  
  
  Compiled files in Go
&lt;/h2&gt;

&lt;p&gt;A slight digression today. I noticed that the compiled size of my “hello, world!” program from yesterday was a whopping 2 megabytes, so I’m going to explore reasons for that along with what happens at compilation time.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kai:~/helloworld/&lt;span class="nv"&gt;$ &lt;/span&gt;ll
total 4200
&lt;span class="nt"&gt;-rwxr-xr-x&lt;/span&gt;  1 kai  staff   2.0M 26 Jan 15:12 helloworld&lt;span class="k"&gt;*&lt;/span&gt;
&lt;span class="nt"&gt;-rw-r--r--&lt;/span&gt;  1 kai  staff    74B 26 Jan 16:43 main.go
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So, of course, the first thing I did was to create an “empty” program that does absolutely nothing. Its source code is as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-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;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="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After running &lt;code&gt;go build&lt;/code&gt; on that, turns out the Mac executable is still 1.1MB. So, the base minimum size for any Go program is over a megabyte. Still, they compile and run extremely quickly, so maybe that’s not a bad thing? We have plenty of bandwidth and memory these days…&lt;/p&gt;

&lt;p&gt;But what are the reasons for such relatively large binary files for things that are so simple, or in the case of the above example, do nothing at all? Turns out, unsurprisingly, it has to do with what’s bundled into the executable. The official Go FAQ &lt;a href="https://golang.org/doc/faq#Why_is_my_trivial_program_such_a_large_binary"&gt;goes into this&lt;/a&gt; in a bit more detail, and compares the build size of a Hello World program in C (750KB or so) and in Go (2MB). The key here is in the concept of static linking. All the packages and required assets are bundled into one thing that gets compiled for a specific computer architecture. That means that my compiled Go program can be sent to anyone with a Mac and it will just run. No requirements to check “oh, do you have X installed?” or “make sure you are running version X of Y”. It just runs. The file size is the price you pay for that.&lt;/p&gt;

&lt;p&gt;The bundled information alongside the raw "this is what your program will do" includes some clever debugging and stack trace information, according to the Go FAQ. This is borne out by the &lt;a href="https://www.cockroachlabs.com/blog/go-file-size/"&gt;analysis done by Raphael 'kena' Poss at Cockroach Labs&lt;/a&gt; which shows that the runtime information, as in "this is what your computer needs to know about running this code" is 900K of any given Go program.&lt;/p&gt;

&lt;p&gt;If I'm only using one (the &lt;code&gt;Println&lt;/code&gt;) method of the &lt;code&gt;fmt&lt;/code&gt; package, is it worth importing the whole thing? The answer, at least to me today, right now, is "yeah". There is zero incentive for me to start learning inventing the wheel to implement some sort of "print to screen" functionality in order to shave off some Kilobytes. I'm not programming for the &lt;a href="https://hackaday.com/2020/04/21/a-jaw-dropping-demo-in-only-256-bytes/"&gt;Demoscene&lt;/a&gt; anyway.&lt;/p&gt;

&lt;p&gt;This interesting sidetrack has got me reading about all the &lt;a href="https://pkg.go.dev/std"&gt;Go standard library&lt;/a&gt;. There's implementations for everything from zipping and unzipping files, as well as encoding and decoding jpeg files. Personally, I've always found it a bit of a mental challenge to find out "has X already been implemented, and how to find out about it?" as well as remembering all of it. I think a good rule of thumb might be to rubber duck as I go and google "how to do  in " pretty much before I do anything new to avoid an embarrassment of "uh, why have you implemented a horrendously inefficient way to do this when there's a perfectly good internal method provided by the standard library?"&lt;/p&gt;

&lt;h2&gt;
  
  
  References and further reading
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://pkg.go.dev/std"&gt;Go Standard Library&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.cockroachlabs.com/blog/go-file-size/"&gt;“Why are my Go executable files so large?” on Cockroach Labs&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://golang.org/doc/faq#Why_is_my_trivial_program_such_a_large_binary"&gt;“Why is my trivial program such a large binary?"&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Cover image: Photo by &lt;a href="https://unsplash.com/@freestocks?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText"&gt;freestocks on Unsplash&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Short one for today, as I have had a headache all day. Hopefully more in-depth tomorrow.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Getting Going with Go, Day 2</title>
      <dc:creator>Kai</dc:creator>
      <pubDate>Tue, 26 Jan 2021 17:21:59 +0000</pubDate>
      <link>https://dev.to/kaipmdh/getting-going-with-go-day-2-1gjd</link>
      <guid>https://dev.to/kaipmdh/getting-going-with-go-day-2-1gjd</guid>
      <description>&lt;p&gt;&lt;a href="https://dev.to/kaipmdh/getting-going-with-go-day-1-bkl"&gt;Yesterday, I outlined&lt;/a&gt; what I was looking to do and achieve with this learning diary, and got set up with Go by installing it and an extension for VSCode to help us along.&lt;/p&gt;

&lt;p&gt;Today, I'm going to write my first Go program. Baby steps!&lt;/p&gt;

&lt;h2&gt;
  
  
  Hello, World!
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Writing the program
&lt;/h3&gt;

&lt;p&gt;Today's task is to be writing the classic starter program for any language, one that outputs a "hello world" message to the screen. I'll try to go through the code line by line and come to an understanding of what it does. Of course, this is only scratching the surface, but shows the structure of the language.&lt;/p&gt;

&lt;p&gt;Let's start in a directory called &lt;code&gt;helloworld&lt;/code&gt;, where we will create a file called &lt;code&gt;main.go&lt;/code&gt;. Into &lt;code&gt;main.go&lt;/code&gt; we'll put the following, which I've marked with line numbers. You'll need to leave them out when you type your program in:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="m"&gt;1&lt;/span&gt; &lt;span class="k"&gt;package&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;
&lt;span class="m"&gt;2&lt;/span&gt; 
&lt;span class="m"&gt;3&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="s"&gt;"fmt"&lt;/span&gt;
&lt;span class="m"&gt;4&lt;/span&gt; 
&lt;span class="m"&gt;5&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="m"&gt;6&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;"Hello, World!"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="m"&gt;7&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Before we get antsy and run the program, let's run through what we've written line by line.&lt;/p&gt;

&lt;p&gt;Line 1, &lt;code&gt;package main&lt;/code&gt; is our definition where we say that this package we are writing is to be the main executable of our program. If we were to create other packages that we use in our program, we would have to declare them as such in their own files.&lt;/p&gt;

&lt;p&gt;Line 3, &lt;code&gt;import "fmt"&lt;/code&gt; says that within this program of ours, we'd like to use the &lt;code&gt;fmt&lt;/code&gt; package. &lt;code&gt;fmt&lt;/code&gt; is part of the Go standard library. It provides for formatting functionality of input and output, which means that we can use it to print to the screen. Fairly fundamental stuff. If your program wasn't ever going to print any output or take in any input, you wouldn't need to import the &lt;code&gt;fmt&lt;/code&gt; package, saving on your program's footprint.&lt;/p&gt;

&lt;p&gt;Line 5 is the start of our &lt;code&gt;main&lt;/code&gt; function. &lt;code&gt;main()&lt;/code&gt; is a special type of function , which is the one that gets executed first when the program is called. Think of it as the doorway into the program. Having this structure makes sense, as Go aims to build and improve on standards and structure set by the C family of languages.&lt;/p&gt;

&lt;p&gt;Functions in Go are defined with the syntax &lt;code&gt;func functionname()&lt;/code&gt; and a pair of braces / curly brackets (&lt;code&gt;{}&lt;/code&gt;). In the case of our program above, the function &lt;code&gt;main&lt;/code&gt;, including its declaration and delimiter braces, encompasses lines 5-7.&lt;/p&gt;

&lt;p&gt;Line 6 is the command to print our message to the screen. It uses the &lt;code&gt;Println&lt;/code&gt; (print line) method of the &lt;code&gt;fmt&lt;/code&gt; package, with the contents to be printed enclosed in parentheses. Because we are printing text, it needs to be enclosed in quotation marks. You can of course play around with the contents of the string "Hello, World!" to have it print whatever you want. Just make sure that you enclose everything you need to be shown on the screen by the &lt;code&gt;Println&lt;/code&gt; method in quotation marks. It won't work if you don't.&lt;/p&gt;

&lt;p&gt;Line 7 rounds out our &lt;code&gt;main&lt;/code&gt; function by closing it off with the closing brace. If you wouldn't, the computer wouldn't know where the thing is meant to end, and running the program would fail.&lt;/p&gt;

&lt;h3&gt;
  
  
  Running our program
&lt;/h3&gt;

&lt;p&gt;Unlike interpreted languages like Python or Ruby, we can't "just run" our program. Instead, we'll have to &lt;em&gt;build&lt;/em&gt; it to an executable:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kai:~/helloworld/ &lt;span class="nv"&gt;$ &lt;/span&gt;go build 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This packages everything we need to run the program into machine-readable code. If there were no errors, you should see no output, but when you list the files in the directory, you should see an executable file called &lt;code&gt;helloworld&lt;/code&gt;, the same as the directory it's in.&lt;/p&gt;

&lt;p&gt;If you run the executable, you should see your program output a friendly greeting!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kai:~/helloworld/ &lt;span class="nv"&gt;$ &lt;/span&gt;./helloworld
Hello, World!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Editing our program
&lt;/h3&gt;

&lt;p&gt;If you wanted to change the output of the text from "Hello, World" to something else, you would need to save the file and run &lt;code&gt;go build&lt;/code&gt; again. Changes to your compiled program won't appear if you just make them in the source code.&lt;/p&gt;

&lt;h2&gt;
  
  
  References and Further Reading
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://wwwx.cs.unc.edu/~sparkst/howto/cpp_main.php"&gt;How To: C/C++ Main&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://gist.github.com/prologic/5f6afe9c1b98016ca278f4d507e65510"&gt;James Mills' "Learn Go in Five Minutes" GitHub gist&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://golang.org/pkg/fmt/"&gt;Package fmt documentation&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://thenewstack.io/understanding-golang-packages/"&gt;"Understanding Golang Packages" on The New Stack&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Cover image: Photo by &lt;a href="https://unsplash.com/@drscythe?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText"&gt;Dominik Scythe on Unsplash&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Next, I think we'll look a little bit deeper into compiling our program and Go modules.&lt;/p&gt;

</description>
      <category>codenewbie</category>
      <category>programming</category>
      <category>go</category>
    </item>
    <item>
      <title>Getting Going with Go, Day 1</title>
      <dc:creator>Kai</dc:creator>
      <pubDate>Mon, 25 Jan 2021 16:05:30 +0000</pubDate>
      <link>https://dev.to/kaipmdh/getting-going-with-go-day-1-bkl</link>
      <guid>https://dev.to/kaipmdh/getting-going-with-go-day-1-bkl</guid>
      <description>&lt;h2&gt;
  
  
  The Why of this exercise
&lt;/h2&gt;

&lt;p&gt;Yesterday, on my birthday, I decided to start documenting my daily progress on exploring a new programming language: Go. It’s not going to be quite a #100DaysofCode, as I aim to have it be more concise than a hundred days, but I will try to document every day’s progress, no matter how small or inconsequential-seeming at the time. I will include references to materials I used, as well as further reading at the bottom of each article (I did spend years in academia, after all…) so hopefully you will find something of interest there.&lt;/p&gt;

&lt;p&gt;This is the first instalment, where we get set up and ready to Go. I am using a Mac, so any instructions and code below will be from that vantage point, but similar commands will exist for Linux and other operating systems as well. But first, a bit on the dual reasons I am pursuing this GOal (and why you have to deal with these strained puns).&lt;/p&gt;

&lt;p&gt;Go, sometimes referred to in hashtags as Golang, is a modern programming language originally developed at Google to take in some of the best parts its designers liked in other programming languages, &lt;a href="https://en.wikipedia.org/wiki/Go_(programming_language)"&gt;namely static typing, high performance and usability&lt;/a&gt;. As a project, it tries to marry the three strands of programming not often seen as available together: &lt;a href="https://golang.org/doc/faq#creating_a_new_language"&gt;"One had to choose either efficient compilation, efficient execution, or ease of programming; all three were not available in the same mainstream language"&lt;/a&gt;. So we’re looking at a robust and performant language that aims to not be esoteric or demand deep knowledge of issues such as memory management and garbage collection from a programmer. Sounds good.&lt;/p&gt;

&lt;p&gt;I am a relatively newly-minted software developer. On a daily basis, I chiefly work with Ruby (and Ruby on Rails) meaning I am used to working with an interpreted language, duck typing, a big friendly framework with lots of syntactic sugar giving me nifty helpers, and a robust codebase in my workplace’s application to which I can refer and from which I can crib.&lt;/p&gt;

&lt;p&gt;The chief focus of &lt;a href="https://www.civo.com"&gt;the company I work for&lt;/a&gt; is managed Kubernetes. While I haven’t worked on the underlying infrastructure layer or the operators that make our particular offering work, both they and Kubernetes itself are written in Go. You can see where this is going: I want to be able to understand what is going on when I peek behind the curtain, as well as maybe in the longer term even be able to contribute!&lt;/p&gt;

&lt;p&gt;So, to summarise: I am looking to improve my knowledge of different types of programming languages. With Go being statically typed and compiled, as well as both well-documented and the language used in an element of what my company works with, it makes sense to pick it for study. Nothing quite like diving in head-first, right? At least this way the worst we can do is write programs that just don’t work, rather than hurt ourselves.&lt;/p&gt;

&lt;h2&gt;
  
  
  Installing Go
&lt;/h2&gt;

&lt;p&gt;As mentioned, I’m on a Mac, so I was able to install the tools to build Go code into programs using Homebrew: &lt;code&gt;brew install go&lt;/code&gt;. If you are on another operating system, or are not using Homebrew, your first port of call should be the &lt;a href="https://golang.org/doc/install"&gt;binary distribution for your OS&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;At the time of writing this, brew installed version 1.15 of Go:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ brew install go
==&amp;gt; Downloading https://homebrew.bintray.com/bottles/go-1.15.5.mojave.bottle.tar.gz
==&amp;gt; Downloading from https://d29vzk4ow07wi7.cloudfront.net/70969a6147bad6960136bdea78063d39b527c993a725ad525a3cf6e9f8ad6
######################################################################## 100.0%
==&amp;gt; Pouring go-1.15.5.mojave.bottle.tar.gz
🍺  /usr/local/Cellar/go/1.15.5: 9,784 files, 494.2MB
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let’s make sure everything is set up. If the following command does not work for you, you may need to &lt;a href="https://golang.org/doc/gopath_code.html"&gt;set&lt;/a&gt; your $GOPATH variable to make sure your operating system will know where to look for Go when you run it. Try running &lt;code&gt;go&lt;/code&gt; in your home directory:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kai:~ &lt;span class="nv"&gt;$ &lt;/span&gt;go
Go is a tool &lt;span class="k"&gt;for &lt;/span&gt;managing Go &lt;span class="nb"&gt;source &lt;/span&gt;code.

Usage:

    go &amp;lt;&lt;span class="nb"&gt;command&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;arguments]

The commands are:

    bug         start a bug report
    build       compile packages and dependencies
    clean       remove object files and cached files
    doc         show documentation &lt;span class="k"&gt;for &lt;/span&gt;package or symbol
    &lt;span class="nb"&gt;env         &lt;/span&gt;print Go environment information
    fix         update packages to use new APIs
    &lt;span class="nb"&gt;fmt         &lt;/span&gt;gofmt &lt;span class="o"&gt;(&lt;/span&gt;reformat&lt;span class="o"&gt;)&lt;/span&gt; package sources
    generate    generate Go files by processing &lt;span class="nb"&gt;source
    &lt;/span&gt;get         add dependencies to current module and &lt;span class="nb"&gt;install &lt;/span&gt;them
    &lt;span class="nb"&gt;install     &lt;/span&gt;compile and &lt;span class="nb"&gt;install &lt;/span&gt;packages and dependencies
    list        list packages or modules
    mod         module maintenance
    run         compile and run Go program
    &lt;span class="nb"&gt;test        test &lt;/span&gt;packages
    tool        run specified go tool
    version     print Go version
    vet         report likely mistakes &lt;span class="k"&gt;in &lt;/span&gt;packages

Use &lt;span class="s2"&gt;"go help &amp;lt;command&amp;gt;"&lt;/span&gt; &lt;span class="k"&gt;for &lt;/span&gt;more information about a command.

Additional &lt;span class="nb"&gt;help &lt;/span&gt;topics:

    buildconstraint build constraints
    buildmode       build modes
    c               calling between Go and C
    cache           build and &lt;span class="nb"&gt;test &lt;/span&gt;caching
    environment     environment variables
    filetype        file types
    go.mod          the go.mod file
    gopath          GOPATH environment variable
    gopath-get      legacy GOPATH go get
    goproxy         module proxy protocol
    importpath      import path syntax
    modules         modules, module versions, and more
    module-get      module-aware go get
    module-auth     module authentication using go.sum
    module-private  module configuration &lt;span class="k"&gt;for &lt;/span&gt;non-public modules
    packages        package lists and patterns
    testflag        testing flags
    testfunc        testing functions

Use &lt;span class="s2"&gt;"go help &amp;lt;topic&amp;gt;"&lt;/span&gt; &lt;span class="k"&gt;for &lt;/span&gt;more information about that topic.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Setting up our IDE for Go
&lt;/h2&gt;

&lt;p&gt;The next thing is to prepare my editor to deal with Go. I am using Microsoft’s &lt;a href="https://code.visualstudio.com/"&gt;VSCode&lt;/a&gt;, which has a big plug-in/extension for Go available, along with lots of other extensions that I might explore later. Go code can be edited in any text editor, though, so go wild with whatever you’re comfortable with.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ZYc8lQIb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/dexhs3gp38wao4vz5mxz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ZYc8lQIb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/dexhs3gp38wao4vz5mxz.png" alt="VSCode Go extension"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can get the official VSCode Go extension by searching for “go” in the extensions menu, or &lt;a href="https://code.visualstudio.com/docs/languages/go"&gt;from this site&lt;/a&gt;. I am especially looking forward to utilising the &lt;a href="https://github.com/golang/vscode-go/blob/master/docs/features.md#intellisense"&gt;IntelliSense code completion suggestions and the integrated linter&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;That’s it for today. Coming up next: Taking our setup for a spin and writing our first lines of Go!&lt;/p&gt;

&lt;h2&gt;
  
  
  References and further reading
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://en.wikipedia.org/wiki/Go_(programming_language)"&gt;Go (Programming language) on Wikipedia&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/golang/go/wiki"&gt;The official Go Wiki&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://howistart.org/posts/go/1/"&gt;How I Start: Go&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;If you’d like to try playing with Go without setting anything up locally, the Go Tour runs in your browser: &lt;a href="https://tour.golang.org/welcome/1"&gt;https://tour.golang.org/welcome/1&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href="https://golang.org/doc/faq#creating_a_new_language"&gt;Go FAQ, specifically the section on reasons for creating Go, and its historical antecedents&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/golang/vscode-go/blob/master/docs/features.md"&gt;VSCode Go extension features documentation&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>go</category>
      <category>programming</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>2020 Working From Home Equipment Retrospective (and What I Aim to Upgrade in 2021)</title>
      <dc:creator>Kai</dc:creator>
      <pubDate>Mon, 04 Jan 2021 14:31:11 +0000</pubDate>
      <link>https://dev.to/kaipmdh/2020-working-from-home-equipment-retrospective-and-what-i-aim-to-upgrade-in-2021-3e0a</link>
      <guid>https://dev.to/kaipmdh/2020-working-from-home-equipment-retrospective-and-what-i-aim-to-upgrade-in-2021-3e0a</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--kWOAlAv2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/y40l632bqb11xj18j5o9.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--kWOAlAv2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/y40l632bqb11xj18j5o9.jpg" alt="My home office setup in 2020"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;I am thankful that in 2020 I was able to transition to working from home and that the Covid-19 pandemic didn't affect my employment situation. In fact, I learned a lot about what sorts of things I appreciate about working from an office, and what things I really could do without. This post aims to document some of the equipment I used throughout 2020 to get work done, what I thought about it, and what I hope to upgrade or change in the year that has just started.&lt;/p&gt;

&lt;h2&gt;
  
  
  Hardware
&lt;/h2&gt;

&lt;p&gt;My daily driver computer is my work Macbook Pro from 2015. I am absolutely a fan of the pre-touchbar Macbooks and their longevity. The laptop itself does everything I need it to do as both a web developer and developer advocate. In daily use, I keep it connected to power, on a stand housing my audio interface and USB hub.&lt;/p&gt;

&lt;p&gt;The interface itself is a &lt;a href="https://focusrite.com/en/usb-audio-interface/scarlett/scarlett-2i2"&gt;Focusrite Scarlett 2i2 3rd generation&lt;/a&gt;. I bought it in the summer as a way of plugging in my guitar and being able to play with effects without having to turn on amplifiers and driving the neighbours crazy. I later also plugged in an XLR microphone, more of which later, and I have zero complaints about the Scarlett overall.&lt;/p&gt;

&lt;p&gt;Also evacuated from the office when the UK lockdown started in March 2020 is a &lt;a href="https://displaysolutions.samsung.com/monitor/detail/1041/U28E590"&gt;Samsung U28E590 HD monitor&lt;/a&gt;. I keep the laptop screen on for things like Slack and email that I only look at occasionally, and have my terminal, IDE and the like on the big external screen.&lt;/p&gt;

&lt;h2&gt;
  
  
  Furniture
&lt;/h2&gt;

&lt;p&gt;This is the one section where I dreaded spending money when the situation with working from home was uncertain: would it be worth splashing out on office furniture if it was all going to blow over in a few months? Turns out it didn't blow over, and I'm glad I put in a bit more money than I initially wanted. Three weeks of working at a dining room table was more than enough, thank you.&lt;/p&gt;

&lt;p&gt;I bought a &lt;a href="https://www.wayfair.co.uk/furniture/pdp/mercury-row-kylah-computer-desk-u001749326.html"&gt;Mercury Row computer desk&lt;/a&gt; for two chief reasons: Adjustable feet, as not a single surface in my house is level, and a reasonable 75cm surface height. I'm not especially tall, but I just can't abide dinky desks that I have to slouch over. I have bad enough posture already.&lt;/p&gt;

&lt;p&gt;I threw an &lt;a href="https://www.wayfair.co.uk/furniture/pdp/mercury-row-managers-high-back-executive-chair-elz1267.html"&gt;"executive chair"&lt;/a&gt; into the same order, and it's okay. The gas spring started sagging within a few months, for which they partially refunded me and I've been too lazy to get a third-party replacement. What annoys me is that the armrests have zero adjustment possibility, meaning I have to change seats or stand up if I want to play some guitar at lunch or after work.&lt;/p&gt;

&lt;h2&gt;
  
  
  Peripherals
&lt;/h2&gt;

&lt;p&gt;I joined the clicky keyboard crew in 2020, when I wanted a smaller form-factor keyboard to not require me to reach so far for the trackpad. So I bought a &lt;a href="https://www.keychron.com/pages/k6"&gt;Keychron K6&lt;/a&gt; with Gateron Brown switches, which I promptly customised with uniform-height DSA profile keycaps. I like that it is a multi-device Bluetooth keyboard and has separate modes for MacOS, Windows and Android.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--piAVB8DY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/n9t6flmq8lh3gg5mzd9r.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--piAVB8DY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/n9t6flmq8lh3gg5mzd9r.jpg" alt="Tap-to-click cat"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For a mouse, I have an Apple Magic Trackpad 2 configured with tap-to-click. It's the first thing I turn on with any trackpad, and wouldn't want to live without it. As I don't do any precision work with the mouse, having a stand-alone trackpad is great because I don't have to change the orientation of my hand or anything when moving from the keyboard to it. I'd still like to minimize the use of a mouse and the rotation from the elbow and shoulder further, though.&lt;/p&gt;

&lt;p&gt;My headphones are a pair of Sony's &lt;a href="https://www.sony.co.uk/electronics/headband-headphones/wh-1000xm3"&gt;WH-1000XM3 noise-canceling headphones&lt;/a&gt;, but I tend to use them wired up to the Focusrite Scarlett rather than wireless or with the noise-canceling turned on. I know a lot of people swear by the Bose QC series, but they just didn't feel as nice to my head as the Sonys do. My main gripe with the WH-1000XM3s are the absolutely dreadful touch panel controls that I had to just turn off when using them wirelessly, followed by the fact that the 3.5mm jack socket is set so deep that most cables aside from the one supplied with the headphones won't fit.&lt;/p&gt;

&lt;p&gt;My microphone, not pictured above as it was a later purchase, is a &lt;a href="https://www.tonormic.com/products/tc20-xlr-microphone"&gt;Tonor TC-20&lt;/a&gt;. Given my office room isn't treated in any way for acoustics, it sounds lovely. The boom arm and mount feel solid, and the clamp to the desk has been improved and increased from pictures I've seen online. For a £45 (US$60) combo, it was a really good purchase. Even if I were to upgrade the mic itself the shock mount and boom can be used. Obviously, being an XLR microphone it requires an external interface, but for that I have the Scarlett.&lt;/p&gt;

&lt;h2&gt;
  
  
  Software
&lt;/h2&gt;

&lt;p&gt;I use VSCode as my main IDE. Whether it's doing Ruby on Rails work for Civo's website, or writing scripts or YAML, I find that the various linters, theming options and source control tools are really helpful. Picking changes in code merges is actually about as pleasurable as I can imagine it ever being. It is heavy and occasionally takes a while to get started, but I guess that's the price you pay for all the tooling loaded in. (If anyone wants to help me set up &lt;code&gt;vim&lt;/code&gt; to look and feel like VSCode, I'm all ears.)&lt;/p&gt;

&lt;p&gt;I'm bad at using the integrated VSCode terminal. Instead I tend to Command-tab to iTerm. One of the things I'd like to learn to do more with in 2021 is tmux and the like. I've always been super impressed when colleagues do demos of multiple panes running commands and updating with changes.&lt;/p&gt;

&lt;p&gt;After far too many years of memorizing increasingly complex passwords, I went all in on &lt;a href="https://1password.com"&gt;1Password&lt;/a&gt; this past year. It's an absolute godsend, really. I honestly feel &lt;em&gt;good&lt;/em&gt; about the fact that I don't even know what my passwords are anymore. Being able to store occasionally-useful strings like frequent flyer numbers (LOL remember when those were useful?) in the same app is really useful. I can't recommend it enough, plus their &lt;a href="https://twitter.com/1Password/status/1328380617382371329"&gt;support is world-class&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I use Firefox to browse the web in normal use, but obviously dabble in Chrome and Safari when I'm doing web dev stuff to make sure it all looks like I need it to.&lt;/p&gt;

&lt;p&gt;For streaming music I use Spotify. I can't say I know of any other streaming service that offers the type of discovery mechanic they have developed. I have my issues with songs repeating on Discover Weekly with suspicious regularity as if labels can pay to get on there, but overall being able to sync across devices and have it everywhere is pretty neat.&lt;/p&gt;

&lt;h2&gt;
  
  
  Other
&lt;/h2&gt;

&lt;p&gt;My home network, before being routed to the Internet via Virgin Media's hub, has a Raspberry Pi 3 running &lt;a href="https://pi-hole.net/"&gt;PiHole&lt;/a&gt; to provide DNS-level ad blocking to all devices in the house. It's a thing you get so used to and don't think about until you see what pages look for others not on your network.&lt;/p&gt;

&lt;h2&gt;
  
  
  Upgrades and changes
&lt;/h2&gt;

&lt;p&gt;As mentioned above, I'd absolutely want to get a different chair. Having adjustable armrests is something I miss a surprising amount, and being on the heavier side of human I worry about all the creaks and other noises from the chair.&lt;/p&gt;

&lt;p&gt;You may notice the conspicuous lack of a camera being mentioned in this post. While I've done a few online meetups, my camera setup does need work and I'd be up for hearing recommendations. I ordered a green screen in November but ended up canceling that order because of reviews that weren't as glowing as I was led to think.&lt;/p&gt;

&lt;p&gt;If I was made of money, I'd absolutely want to get a split ergonomic keyboard like the &lt;a href="https://www.zsa.io/moonlander/"&gt;ZSA Moonlander&lt;/a&gt;. I think they're gorgeous.&lt;/p&gt;

&lt;p&gt;One of my personal 2021 projects is also to integrate PiHole-style ad blocking to the VPN I use while out and about. Obviously, that's not been a priority in the past year given I've hardly left the house!&lt;/p&gt;

</description>
      <category>productivity</category>
      <category>equipment</category>
      <category>workingfromhome</category>
    </item>
    <item>
      <title>Moving conditionally-rendered DOM elements to a dynamic location on a page with jQuery</title>
      <dc:creator>Kai</dc:creator>
      <pubDate>Fri, 27 Nov 2020 17:00:21 +0000</pubDate>
      <link>https://dev.to/kaipmdh/moving-conditionally-rendered-dom-elements-to-a-dynamic-location-on-a-page-with-jquery-3ab6</link>
      <guid>https://dev.to/kaipmdh/moving-conditionally-rendered-dom-elements-to-a-dynamic-location-on-a-page-with-jquery-3ab6</guid>
      <description>&lt;p&gt;For my own reference, and perhaps of help to you, here is how I manipulated the position of DOM elements (a &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt; tag displaying a status message) on a page when it gets rendered, based on the currently active element on the page. This allows for a shorter feedback loop from user action to status update, and keep user focus on what they are doing.&lt;/p&gt;

&lt;p&gt;For this project, I had a controller action check status on the back end based on user input. The status message returned by the controller was best served directly in the relevant element that the user had tested, out of multiple possibilities.&lt;/p&gt;

&lt;p&gt;As the project runs Rails, it displays status messages in the "Flash" message element in the view. It was this flash element I wished to move from the usual place at the top of the screen to the relevant "active" form the user had clicked on to check. So as to not repeat code conditionally and render flash messages specific to each controller method, I decided to use a quick JavaScript/jQuery hack to move the rendered message, encapsulated in its own HTML element, to within the currently-active page element, to give the user the closest feedback to what they needed to do.&lt;/p&gt;

&lt;p&gt;The code itself is a declaration to run a function &lt;code&gt;moveAlerts&lt;/code&gt; once the page loads. The &lt;code&gt;moveAlerts&lt;/code&gt; function is a conditional that checks if there is an element called &lt;code&gt;alert&lt;/code&gt; in the DOM, and if there is, it uses jQuery's &lt;code&gt;prependTo&lt;/code&gt; method to add it to the top of a &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt; that is classed as &lt;code&gt;open&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The code is as follows, and in my case is in a in a "page-specific javascript" block in my view file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;script&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;$&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt; &lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;ready&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;moveAlerts&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;moveAlerts&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getElementsByClassName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;alert&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;$&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;div.alert&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;prependTo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;div.open&lt;/span&gt;&lt;span class="dl"&gt;'&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="p"&gt;}&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To use something like this yourself, you would need to edit it to correspond to elements in your document - you may want to move an element with a different name to "alert", or not have a &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt; called "open" to move the alert into. Of course, if you are not using Rails, you would just need to put the &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; block in the HTML for your page rather than dealing with page-specific javascript blocks.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>jquery</category>
      <category>rails</category>
    </item>
  </channel>
</rss>
