<?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: Fakorede Abiola</title>
    <description>The latest articles on DEV Community by Fakorede Abiola (@fakorede).</description>
    <link>https://dev.to/fakorede</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%2F124558%2Faa54cee3-3e0d-45bf-b4f4-ba1038f1c13e.jpeg</url>
      <title>DEV Community: Fakorede Abiola</title>
      <link>https://dev.to/fakorede</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/fakorede"/>
    <language>en</language>
    <item>
      <title>Variables in GO</title>
      <dc:creator>Fakorede Abiola</dc:creator>
      <pubDate>Sat, 11 Apr 2020 10:12:45 +0000</pubDate>
      <link>https://dev.to/fakorede/variables-in-go-2467</link>
      <guid>https://dev.to/fakorede/variables-in-go-2467</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;GO stores a variable inside a computer memory. A variable occupies some space on the memory depending on the variables type. Variables are only created after you run your program so they only become alive at the runtime not the compile-time.  GO only knows the type at compile-time.&lt;/p&gt;

&lt;p&gt;A variable stores a value with a type because GO is a strongly typed language. This is why we can't store an integer variable inside a variable which has a string type.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Variable Name&lt;/strong&gt; allows us access the variable.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Variable Type&lt;/strong&gt; GO is a statically typed programming language. In GO, every variable has a type. It is called &lt;em&gt;static type&lt;/em&gt; since we can't change the type of a variable once we declare it.&lt;/p&gt;

&lt;p&gt;Since a Variable should have a type, its only important to talk about the basic data types.&lt;/p&gt;

&lt;h2&gt;
  
  
  Basic Data Types
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;int&lt;/strong&gt; - An int type represents numbers without a fractional part. It can be negative, zero, or positive numbers . It ranges from -128 to 127. These are called &lt;em&gt;integer literals&lt;/em&gt;. GO has several built-in integer types for storing signed and unsigned numbers with varying sizes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;float64&lt;/strong&gt; - A float type are used to store numbers with a fractional part ex -2.5, 0.5, 1.5. These are called &lt;em&gt;float literals&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;bool&lt;/strong&gt; - The bool type can only represent two values, &lt;em&gt;true&lt;/em&gt; and &lt;em&gt;false&lt;/em&gt;. These are called boolean values and are pre-declared constants.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;string&lt;/strong&gt; -  The string type is used for representing human readable text data. An example string literal is "hello world!". A string can contain english and non-english characters.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to Declare a Variable
&lt;/h2&gt;

&lt;p&gt;In GO, we need to declare a variable before we can use it unlike in a dynamic language where we can assign a value to a variable even before declaring it. This is important and necessary for the compile-time safety.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var speed int
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;var&lt;/code&gt; keyword which is short for variable starts the variable declaration. It simply tells GO to declare a variable.&lt;/p&gt;

&lt;p&gt;After the var keyword, we need to give a unique name to the variable. Here, &lt;code&gt;speed&lt;/code&gt; is the name of this variable. A variable name can also be referred to as an identifier. It helps us understand which variable we are referring to.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;int&lt;/code&gt; is the type of this variable. In GO, every variable has a type. This is because GO is a &lt;code&gt;strongly-typed&lt;/code&gt; programming language. This helps the compiler find bugs in our program even before we run it. A variable type determines what type of value we can store in it and where we can use it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Naming Rules&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A name should only start with a letter or an underscore character. When the name starts with an uppercase letter, that name becomes exported so that other packages can use it.&lt;/li&gt;
&lt;li&gt;A name can contain uppercase letters.&lt;/li&gt;
&lt;li&gt;A name can have unicode letters. This works because GO can understand unicode letters.&lt;/li&gt;
&lt;li&gt;A name cannot contain reserved keywords.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Zero Values
&lt;/h2&gt;

&lt;p&gt;Now if we try to print this variable to the console, we get 0. This is because a variable gets initialized to a &lt;em&gt;zero value&lt;/em&gt; when its declared without an initial value.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var speed int
fmt.Println(speed) // 0
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Every GO type has a zero value. An empty variable gets a &lt;em&gt;zero value&lt;/em&gt; depending on its type.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var speed int
var temperature float64
var off bool
var name string

fmt.Println(speed) // 0
fmt.Println(temperature) // 0
fmt.Println(off) // false
fmt.Printf("%q\n", name) // ""
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Declaring Multiple Variables
&lt;/h2&gt;

&lt;p&gt;By using a multiple declaration, we can declare multiple variables at once in the same declaration statement.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var (
   speed int
   temperature float64
   off bool
   name string
)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This is exactly the same as the previous declaration. Its purpose is to improve readability. Its better to use this style when you intend to group a few related variables together.&lt;/p&gt;

&lt;p&gt;We can also declare multiple variables that have the same times like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var speed, velocity int
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;We don't have to define the types of each variable if their types are the same.&lt;/p&gt;

&lt;h2&gt;
  
  
  Type Inference
&lt;/h2&gt;

&lt;p&gt;We can declare variables without specifying its type. This is because GO uses what is called &lt;em&gt;Type Inference&lt;/em&gt; which means that GO can figure out the type of the variable automatically.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var age = 10
fmt.Printf("Variable has a type %T\n", age) // int
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Short Declaration
&lt;/h2&gt;

&lt;p&gt;In GO, we don't even need to use the &lt;code&gt;var&lt;/code&gt; keyword. Just the name of the variable and its value is enough. In this case, we use the &lt;em&gt;Short Declaration Syntax&lt;/em&gt; using the &lt;code&gt;:=&lt;/code&gt; operator like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;isSafe := true
fmt.Printf("Variable has a type %T\n", isSafe) // bool
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Multiple Short Declaration
&lt;/h2&gt;

&lt;p&gt;We can declare and initialize multiple variables using short declaration.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;month, day := "April", 11
fmt.Println(month, day) // April 11
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Here "Fab is assigned to name and 22 is assigned to age. The first variable gets the first value and the second variable gets the second value.&lt;/p&gt;

&lt;h2&gt;
  
  
  Redeclaration
&lt;/h2&gt;

&lt;p&gt;Redeclaration allows us to use existing variables in multiple short declaration variables i.e. declaring new variables while assigning values to existing variables.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var firstname string
firstname, lastname := "Nikola", "Tesla"

fmt.Println(firstname, lastname)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;One of the variables must be a new variable or the redeclaration won't work.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  When to Use Declaration vs When to Use Short Declaration
&lt;/h2&gt;

&lt;p&gt;Use normal declaration:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If you don't know the initial value&lt;/li&gt;
&lt;li&gt;When you want to group variables together&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Use short declaration:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If you know the initial value&lt;/li&gt;
&lt;li&gt;To keep the code concise&lt;/li&gt;
&lt;li&gt;For redeclaration&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Blank Identifier
&lt;/h2&gt;

&lt;p&gt;What happens when we don't use declared variables? A variable declared in every block scope should be used or there will be an error.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;func main() {
   var name string // ERROR: name declared and not used
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Running this program will cause a compile-time error because the variable name was declared but not used.&lt;/p&gt;

&lt;p&gt;The &lt;em&gt;Blank Identifier&lt;/em&gt;( _ ) can be used to prevent unused variable error. It is like a black hole which consumes the variable.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;func main() {
   var name string
   _ = name
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Variables are a very important concept of any programming language. Therefore, it is important to understand the work-arounds around them. In this article, the following concepts were introduced:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Variable Declaration&lt;/li&gt;
&lt;li&gt;Zero Values&lt;/li&gt;
&lt;li&gt;Declaring Multiple Variables&lt;/li&gt;
&lt;li&gt;Type Inference&lt;/li&gt;
&lt;li&gt;Short Variable Declaration&lt;/li&gt;
&lt;li&gt;Multiple Short Declaration&lt;/li&gt;
&lt;li&gt;Redeclaration&lt;/li&gt;
&lt;li&gt;Blank Identifiers&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A link has also been provided to the GO Playground to demonstrate everything we have learnt in this lecture. Thanks for reading and any feedback would be much appreciated. 👋🏼&lt;/p&gt;

&lt;h2&gt;
  
  
  Other Articles 📖
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://fabcodes.hashnode.dev/what-the-dollargopath-is-about-ck8stjzhh004y07s129623r3v"&gt;What the $GOPATH is about&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://dev.to/fakorede/what-the-gopath-is-about-2oni"&gt;The Classic Hello World Program in GO&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://hashnode.com/edit/ck8uq9xq700ablcs1rmd4na8w"&gt;An Introduction to GO Packages&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Code Samples - &lt;a href="https://github.com/Fakorede/Learning-Golang"&gt;https://github.com/Fakorede/Learning-Golang&lt;/a&gt;
&lt;/h4&gt;

&lt;h4&gt;
  
  
  GO Playground - &lt;a href="https://play.golang.org/p/bF3u5v-Er39"&gt;https://play.golang.org/p/bF3u5v-Er39&lt;/a&gt;
&lt;/h4&gt;

</description>
      <category>golanguage</category>
      <category>beginners</category>
      <category>go</category>
    </item>
    <item>
      <title>The Classic Hello World Program in GO</title>
      <dc:creator>Fakorede Abiola</dc:creator>
      <pubDate>Thu, 09 Apr 2020 13:50:34 +0000</pubDate>
      <link>https://dev.to/fakorede/the-classic-hello-world-program-in-go-d6b</link>
      <guid>https://dev.to/fakorede/the-classic-hello-world-program-in-go-d6b</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;To write your first code in any programming language, it has become a norm to start with a simple hello world program. In this post, I will be showing how to write a program in GO and explain all the parts of the program. Lets begin!👍🏼&lt;/p&gt;

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

&lt;p&gt;The first step is creating a helloworld folder in your &lt;code&gt;$GOPATH&lt;/code&gt;. To learn more about how to do this, view my previous article &lt;a href="https://dev.to/fakorede/what-the-gopath-is-about-2oni"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;In the &lt;code&gt;main.go&lt;/code&gt; file, write the following piece of code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package main

import "fmt"

func main() {
   fmt.Println("Hello World!")
}

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



&lt;h2&gt;
  
  
  Explanation
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;package main&lt;/code&gt;  should always be first statement in a GO program. This creates an executable GO program. Every GO file can only belong to a single package.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;main&lt;/code&gt;  represents the name of the package which this file belongs to.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;import&lt;/code&gt;: The import keyword is used to import reusable pieces of code from other packages to use in our program.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;import fmt&lt;/code&gt;: This line imports the fmt package. &lt;a href="https://golang.org/pkg/fmt/"&gt;fmt&lt;/a&gt; is a package that ships with the GO standard library and is used for formatted I/O.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;func main&lt;/code&gt; is an entry point to this program. It is a special function which tells GO where to start execution. In all executable programs, almost everything will be run under this function.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;func&lt;/code&gt; represents a function. A function contains a block of code that can be executed when the function is called. It is used for reusable code.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;fmt.Println&lt;/code&gt;: This line prints "Hello World" to the terminal when the program is run. &lt;a href="https://golang.org/pkg/fmt/#Println"&gt;Println&lt;/a&gt; is a method of the fmt package that writes to the standard output.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Running the Program
&lt;/h2&gt;

&lt;p&gt;There are two(2) tools available to run a GO program.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;go build&lt;/strong&gt;: this command compiles the GO program and we can then run afterwards. First we compile the program using:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ go build
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;It seems as though nothing happened but in the background, this compiles the GO code to machine code. We need to use the &lt;code&gt;ls&lt;/code&gt; command to see the executable file. And then we run it by typing &lt;code&gt;./helloworld&lt;/code&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;This way of running GO programs is best suited for deployment.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;go run&lt;/strong&gt;: this command both compiles and run the GO program.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ go run main.go
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;This is the most suitable for prototyping i.e. when developing&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;That is all when trying to write and run your first program in GO. With this, we should be able to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;understand the basic parts of a GO program.&lt;/li&gt;
&lt;li&gt;what statements like the package main and import clause does.&lt;/li&gt;
&lt;li&gt;how to print to the console.&lt;/li&gt;
&lt;li&gt;how to run a GO program.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Other Articles 📖
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://dev.to/fakorede/what-the-gopath-is-about-2oni"&gt;What the $GOPATH is about&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://fabcodes.hashnode.dev/an-introduction-to-go-packages-ck8uq9xq700ablcs1rmd4na8w"&gt;An Introduction to GO Packages&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Code Samples - &lt;a href="https://github.com/Fakorede/Learning-Golang"&gt;https://github.com/Fakorede/Learning-Golang&lt;/a&gt;
&lt;/h4&gt;

</description>
      <category>golanguage</category>
      <category>beginners</category>
      <category>go</category>
    </item>
    <item>
      <title>What the $GOPATH is about</title>
      <dc:creator>Fakorede Abiola</dc:creator>
      <pubDate>Thu, 09 Apr 2020 13:50:34 +0000</pubDate>
      <link>https://dev.to/fakorede/what-the-gopath-is-about-2oni</link>
      <guid>https://dev.to/fakorede/what-the-gopath-is-about-2oni</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;I just recently started learning the GO programming language. While I have realized that keeping notes of what I am learning along the way is crucial to the learning process, I also decided to as well share some of my notes in the form of short articles revolving around everything I have learnt.&lt;/p&gt;

&lt;p&gt;I almost skipped knowing what the &lt;code&gt;$GOPATH&lt;/code&gt; is about all together as it wasn't discussed properly in the first resource I tried learning GO with. But from what I have gathered, I realize it is important to understand what the &lt;code&gt;$GOPATH&lt;/code&gt; is and understand how it works.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is $GOPATH?
&lt;/h2&gt;

&lt;p&gt;I'll be answering this in a bullet point format to make it easier to digest. Here are some of the points I gathered:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The &lt;code&gt;$GOPATH&lt;/code&gt; is an environment variable. It shows a location to a physical directory on a machine which has GO set up.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The &lt;code&gt;$GOPATH&lt;/code&gt; directory is automatically created under the &lt;code&gt;users&lt;/code&gt; folder when the Visual Studio Code &lt;a href="https://marketplace.visualstudio.com/items?itemName=ms-vscode.Go"&gt;GO extension&lt;/a&gt; is installed so we do not need to create it.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;By default, GO assumes that the folder &lt;code&gt;$GOPATH&lt;/code&gt; shows is in your &lt;code&gt;users&lt;/code&gt; folder. So we do not need to set it.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;To know what your &lt;code&gt;$GOPATH&lt;/code&gt; is, use the command below in your terminal:&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ go env GOPATH
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;It is usually in the form &lt;code&gt;Users/{user}/go&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The directory &lt;code&gt;$GOPATH&lt;/code&gt; points to is also referred to as a &lt;strong&gt;Workspace&lt;/strong&gt;. It also shows GO tools where it can find GO source code files and other related stuffs like compiled packages, executable binaries and so on. By convention, every GO project uses this folder.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Inside this directory are three folders: &lt;code&gt;bin&lt;/code&gt;, &lt;code&gt;pkg&lt;/code&gt;, and &lt;code&gt;src&lt;/code&gt;. The &lt;code&gt;src&lt;/code&gt; folder contains GO source-code files and this is where we keep our GO projects.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;When we download a GO project, it is stored under the &lt;code&gt;$GOPATH&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;An executable GO program needs its own directory which we create under the &lt;code&gt;$GOPATH/src&lt;/code&gt; folder. For example:&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$GOPATH/src/helloworld/main.go
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;If you have a GitHub account, it is better to put your project in a &lt;code&gt;github.com&lt;/code&gt; folder under the &lt;code&gt;src&lt;/code&gt; directory i.e.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$GOPATH/src/github.com/{your-username}/helloworld/main.go
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt; Since we will be creating our projects under the &lt;code&gt;$GOPATH/src&lt;/code&gt; folder, to open up the folder in VS Code using the terminal, if you're on MAC or have git bash installed on Windows, type:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ code ~/go/src
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Looking back, I realize how vital understanding what the &lt;code&gt;$GOPATH&lt;/code&gt; is as a GO developer and how important its concept is in developing GO programs and packages. It is in fact a convention in the GO community and I would definitely urge anyone new to the language to endeavour to understand what it is.&lt;/p&gt;

&lt;h2&gt;
  
  
  Other Articles 📖
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://fabcodes.hashnode.dev/the-classic-hello-world-program-in-go-ck8syp9cm00380fs12jyrolnh"&gt;The Classic Hello World Program in GO&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://fabcodes.hashnode.dev/an-introduction-to-go-packages-ck8uq9xq700ablcs1rmd4na8w"&gt;An Introduction to GO Packages&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Code Samples - &lt;a href="https://github.com/Fakorede/Learning-Golang"&gt;https://github.com/Fakorede/Learning-Golang&lt;/a&gt;
&lt;/h4&gt;

</description>
      <category>golanguage</category>
      <category>beginners</category>
      <category>go</category>
    </item>
    <item>
      <title>Is Node.js really Single Threaded? Here is what I think...</title>
      <dc:creator>Fakorede Abiola</dc:creator>
      <pubDate>Sat, 19 Oct 2019 07:32:14 +0000</pubDate>
      <link>https://dev.to/fakorede/is-node-js-really-single-threaded-here-is-what-i-think-30hm</link>
      <guid>https://dev.to/fakorede/is-node-js-really-single-threaded-here-is-what-i-think-30hm</guid>
      <description>&lt;p&gt;This is a very popular question in the node.js ecosystem. One that has been asked over and over again. And while many believe node.js really is single-threaded, in my opinion, i believe to really answer this question we will have to take a dive into the internals of node.js.&lt;/p&gt;

&lt;p&gt;To really understand this article, I assume the reader understands how Node.js uses the &lt;strong&gt;Event Loop&lt;/strong&gt; to handle the asynchronous code we write as many performance concerns about Node.js eventually boils down to how the Event Loop behaves.&lt;/p&gt;

&lt;h2&gt;
  
  
  Building Blocks Of Node.js
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--fFK4Wv-a--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1571448245688/jtfK9mYFU.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fFK4Wv-a--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1571448245688/jtfK9mYFU.png" alt="nodejs2.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Node.js is a runtime environment for executing JavaScript code outside of a browser. Node.js internally has a collection of dependencies it uses to execute the JavaScript code we write.&lt;/p&gt;

&lt;p&gt;The most important of these dependencies are the &lt;strong&gt;V8 project&lt;/strong&gt; and the &lt;strong&gt;libuv project&lt;/strong&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The &lt;strong&gt;V8 project&lt;/strong&gt; is an open source JavaScript engine created by Google to execute JavaScript code in the browser.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;Libuv project&lt;/strong&gt; is a C++ open source project that gives Node.js access to the Operating systems' underlying file system, networking and as well handles some aspects of concurrency.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;When we start up a node program on our computer, node automatically creates one thread and executes all of our code in that single thread. Inside that thread, we have the &lt;strong&gt;event loop&lt;/strong&gt; which we can think of as a structure that determines what the thread should be doing at any given instance. Every node program has exactly one event loop which is at the core of the program.&lt;/p&gt;

&lt;h2&gt;
  
  
  Is Node Single Threaded?
&lt;/h2&gt;

&lt;p&gt;Before i go in deeper, i have to make two points absolutely clear&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The Node Event Loop itself is &lt;strong&gt;Single Threaded&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Some of the functions included in the Node standard library are &lt;strong&gt;not Single Threaded&lt;/strong&gt;. Which means some of the functions included in Node run outside of our event loop and outside that single thread. 
So, simply declaring that Node is single-threaded is not absolutely true.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In this article, we are going to look at a couple of examples of that by writing and executing some codes at the command line.&lt;/p&gt;

&lt;p&gt;In your code editor, create a new file and name it &lt;code&gt;threads.js&lt;/code&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Require the pbkdf2 function from the crypto module&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;We will run the function and benchmark how long it takes to run on our individual computers. We are not concerned here how the function runs.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const crypto = require('crypto')

const start = Date.now()
crypto.pbkdf2('a', 'b', 100000, 512, 'sha512', () =&amp;gt; {
      console.log('1:', Date.now() - start)
})
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now lets see how long it takes the program to run. In your terminal, run&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;node threads.js&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--vErQOttI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1571450032878/oEexbSY6_.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vErQOttI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1571450032878/oEexbSY6_.png" alt="threads1.PNG"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For me, it takes aprox. 1600 milliseconds. Now lets duplicate the function and run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const crypto = require('crypto')

const start = Date.now()
crypto.pbkdf2('a', 'b', 100000, 512, 'sha512', () =&amp;gt; {
      console.log('1:', Date.now() - start)
})

crypto.pbkdf2('a', 'b', 100000, 512, 'sha512', () =&amp;gt; {
      console.log('2:', Date.now() - start)
})
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;I have to make it clear that both functions will be invoked at approx the same time. With that in mind, lets run the program again&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;node threads.js&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--p1K8B2hs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1571450409472/10JM4UBAy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--p1K8B2hs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1571450409472/10JM4UBAy.png" alt="threads2.PNG"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We will notice that the times we are having now is above what we had before.&lt;/p&gt;

&lt;p&gt;Now, to really understand the significance of the results we had above, i will use the diagram below&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---pCiryYB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1571451735964/IQG60E-iB.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---pCiryYB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1571451735964/IQG60E-iB.png" alt="threads3.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The above is a diagram of the results we would have expected to see if node were truely single-threaded.&lt;/p&gt;

&lt;p&gt;If Node really was single-threaded, this is what we would have expected.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--hYsIaiUd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1571452915458/lbRr68hBY.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hYsIaiUd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1571452915458/lbRr68hBY.png" alt="threads4.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But in reality, this is what really happened:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--n06r9Dw0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1571453136729/VDXGkfcBt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--n06r9Dw0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1571453136729/VDXGkfcBt.png" alt="threads5.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The pbkdf2 functions took approximately 2seconds to run. Clearly, this tells us something happened that went against the single-thread set up of Node because if we were running on only one single thread, we would have seen the first function call complete and then the second one execute.&lt;/p&gt;

&lt;h2&gt;
  
  
  What really happened?
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--wBqwZJc4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1571453557624/7Z27TaAcm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wBqwZJc4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1571453557624/7Z27TaAcm.png" alt="threads6.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The way the pbkdf2() function in the node crypto module works is that it has both the JavaScript and the C++ implementation. But behind the scenes it delegates all the work to be done to the C++ side which contains refernces to the Libuv library which gives Node.js access to the underlying Operating System.&lt;/p&gt;

&lt;p&gt;For some standard library function calls, the Node's C++ side and libuv decides to do expensive operations outside of the event loop entirely. Instead they make use of what is called a &lt;strong&gt;Threadpool&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The Threadpool is a series of four threads that can be used for running computation intensive tasks such as the pbkdf2() function. By default, libuv created four threads in this threadpool. That means that in addition to the thread used for the event loop, there are four other threads that can be used to handle expensive operations that occur in our applications which some functions in the Node standard library make use of.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;While the Event Loop in Node.js is single-threaded, It isn't entirely true that Node.js is single-threaded because there are some other threads available in the libuv Threadpool which Node.js uses in doing computational intensive tasks.&lt;/p&gt;

</description>
      <category>node</category>
      <category>backend</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
