<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Nikita Acharya on Medium]]></title>
        <description><![CDATA[Stories by Nikita Acharya on Medium]]></description>
        <link>https://medium.com/@nikita.acharya8?source=rss-aaf42b61ed5d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*MoBji1YW1-qg2XCM.</url>
            <title>Stories by Nikita Acharya on Medium</title>
            <link>https://medium.com/@nikita.acharya8?source=rss-aaf42b61ed5d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 16:56:35 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@nikita.acharya8/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[GoLang for Ruby developers]]></title>
            <link>https://medium.com/devnetwork/golang-for-ruby-developers-c0a0ce19e367?source=rss-aaf42b61ed5d------2</link>
            <guid isPermaLink="false">https://medium.com/p/c0a0ce19e367</guid>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[programming-languages]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[ruby]]></category>
            <dc:creator><![CDATA[Nikita Acharya]]></dc:creator>
            <pubDate>Wed, 14 Nov 2018 08:48:08 GMT</pubDate>
            <atom:updated>2020-08-13T02:20:02.922Z</atom:updated>
            <content:encoded><![CDATA[<h3>Go for Ruby developers</h3><h4>Rubyists to gophers</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rmrTI4ygtL5Oyp7eOro30g.png" /></figure><p>If you are a <strong>Ruby</strong> developer and want to start with this new language <strong>Go</strong>, this can help you get started. In this blog, we will go through the basics and some cool features of GO along with its Ruby equivalent.</p><blockquote>Ruby is a dynamic, interpreted, reflective, object-oriented, general-purpose programming language. It was designed and developed in the mid-1990s by Yukihiro “Matz” Matsumoto in Japan.<br>According to the creator, Ruby was influenced by Perl, Smalltalk, Eiffel, Ada, and Lisp. It supports multiple programming paradigms, including functional, object-oriented, and imperative. It also has a dynamic type system and automatic memory management.</blockquote><blockquote>Go (often referred to as Golang) is a programming language designed by Google engineers Robert Griesemer, Rob Pike, and Ken Thompson. Go is a statically typed, compiled language in the tradition of C, with the added benefits of memory safety, garbage collection, structural typing, and CSP-style concurrency. The compiler, tools, and source code are all free and open source.</blockquote><blockquote>— Wikipedia</blockquote><p>Let’s start with our all-time example of printing “Hello World” for both Go and Ruby.</p><h4>Ruby</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/af40c577eddb85222d3ef076b9dee078/href">https://medium.com/media/af40c577eddb85222d3ef076b9dee078/href</a></iframe><h3>Go</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cfd1ea578e2db312e62ae3b286a31bd4/href">https://medium.com/media/cfd1ea578e2db312e62ae3b286a31bd4/href</a></iframe><p>Unlike Ruby where we can print “Hello World” with a single line of code, in Go, we need to write a few more lines of code. Let’s get deeper into the Go code.</p><p>In the Go program above, the keyword packagedefines the scope of the code i.e whether it is a library or an executable code. In the above example, with package main we are telling the Go compiler that the code is executable. Every executable program must always use package main.</p><p>The import is similar to require in Ruby, which pulls in external packages that will be used in the program. Here we are pulling the package “fmt” which is used for the input/output formatting.</p><p>The main() function is the entry point for the program execution. All the codes that need to be executed and run in Go, go inside this main function. In Go, opening curly bracket signifies there is code below it that needs to be executed and closing bracket signifies the end of the statement. So, the opening bracket must be on the same line of any block statement like functions, conditions.</p><h3>How to run the code through the command line</h3><h4>Ruby</h4><p>Copy the above ruby code to a file named hello_world.rb. “.rb” is the extension for Ruby source code. We can run a code in ruby using the command ruby &lt;filename&gt;</p><pre>&gt; ruby hello_world.rb<br>Hello World!!!</pre><h4>Go</h4><p>Copy the above Go code to a file named hello-world.go. “.go” is the extension for Go source code. We can run a Go program in two ways which are shown below.</p><pre>&gt; go build hello-world.go<br>&gt; ./hello-world<br>Hello World!!!</pre><p>OR</p><pre>&gt; go run hello-world.go<br>Hello World!!!</pre><p>Here, in the first one, we are first compiling the file and creating an executable binary file using the build command and then running the binary file. While in the second one, we are running the code using the <strong>go run</strong> command. This command creates the executable file behind the scene and then runs the code.</p><h3>Commenting out code</h3><p>In ruby “<strong>#</strong>” is used for commenting the code while in Go we use “<strong>//</strong>”. For multi-line code comment, it is “<strong>/* …. */</strong>”.</p><h4>Ruby</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7fe188c0382a0f8831ac16f92c001b64/href">https://medium.com/media/7fe188c0382a0f8831ac16f92c001b64/href</a></iframe><h4>Go</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ab1fe85554864dba633c7e8cb83a1a0c/href">https://medium.com/media/ab1fe85554864dba633c7e8cb83a1a0c/href</a></iframe><h3>Variable</h3><p>As Ruby is dynamically typed, there is no need to define variable types. While Go being a statically typed language, we need to define the type during the declaration.</p><h4>Ruby</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7edd40137215ebea717b880a20a200ca/href">https://medium.com/media/7edd40137215ebea717b880a20a200ca/href</a></iframe><h4>Go</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ec8e860c85108bf6eafe8fe144373a77/href">https://medium.com/media/ec8e860c85108bf6eafe8fe144373a77/href</a></iframe><p>As we can see in the above example, though Go is a statically typed language, it gives the feel of dynamic type by evaluating the value assigned and declaring the type to the variable on the fly.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/41f5036b43d7cc5f0d1761e418c85fb3/href">https://medium.com/media/41f5036b43d7cc5f0d1761e418c85fb3/href</a></iframe><h3>Data Types</h3><p>Some of the variable data types declarations for Go are listed below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0b0efc28746ad5d7724218757672d45e/href">https://medium.com/media/0b0efc28746ad5d7724218757672d45e/href</a></iframe><p>In Ruby, we can assign a different data type value to an already defined variable of different type but is not possible in Go.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a5fced2d3cf710fe230ff07a6a99d031/href">https://medium.com/media/a5fced2d3cf710fe230ff07a6a99d031/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6e8baa72c46e306a895aa42bef24b261/href">https://medium.com/media/6e8baa72c46e306a895aa42bef24b261/href</a></iframe><h3>Hash/Map</h3><p>As in Ruby, we can also define a hash object in Go. In Go, hash is called <strong>map. </strong>The type syntax for the map is <strong>map[string] int, </strong>where the datatype inside bracket specifies the key data type and the other one, at last, specifies the type of value.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5bb49cdba5630fd6838777c60ebc459d/href">https://medium.com/media/5bb49cdba5630fd6838777c60ebc459d/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8c88ad51c1eaf057e94e7e9d5b531111/href">https://medium.com/media/8c88ad51c1eaf057e94e7e9d5b531111/href</a></iframe><h4>Check if a key is present in the map</h4><p>We can check if a key is present in the map with a two-value assignment. In the example below, if the name has key “last_name”, then “ok” is true and the lastname variable holds the lastname value else “ok” is false.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/54f7ca6493a6758613de434f046c41b7/href">https://medium.com/media/54f7ca6493a6758613de434f046c41b7/href</a></iframe><h3>Array</h3><p>Like in Ruby, we have an array in Go as well. However, in Go, we will need to define the length of the array during the declaration.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d7eb81df9831b749cece282038dd5c42/href">https://medium.com/media/d7eb81df9831b749cece282038dd5c42/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/864734f686674fcef5f7681fd94a59c8/href">https://medium.com/media/864734f686674fcef5f7681fd94a59c8/href</a></iframe><h3>Slice</h3><p>Arrays are limiting for cases when the values of array changes in runtime. Arrays also do not provide the ability to get subarray. For this, Go has a data type called <strong>slices. </strong>Slices store sequence of elements and can be expanded at any time. Slice declaration is as similar as array declaration without the capacity defined:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cf45b5247d2e4a2f0371070a9189e3f4/href">https://medium.com/media/cf45b5247d2e4a2f0371070a9189e3f4/href</a></iframe><p>Now, let’s look into some of the cool uses of slice and compare it with Ruby.</p><h4>Append elements to Array</h4><p>In Ruby, we use <strong>+</strong> operator to append elements of an array to another array. While in Go, we use <strong>append</strong> function to append elements to an array/slice.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/16eb72a0d1c21a748342773fc783bcb2/href">https://medium.com/media/16eb72a0d1c21a748342773fc783bcb2/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/85525f400084e04d00b59180be3e124b/href">https://medium.com/media/85525f400084e04d00b59180be3e124b/href</a></iframe><h4>Sub Slicing Array</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ffbacced6941434034dfd0396c90697b/href">https://medium.com/media/ffbacced6941434034dfd0396c90697b/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1ac46adb67137753be8103fb427c11e0/href">https://medium.com/media/1ac46adb67137753be8103fb427c11e0/href</a></iframe><h3>Copy Slice/Array</h3><p>In Ruby, we can simply copy an array to another one by assigning one array variable to another. While in Go, we cannot copy slices directly using assignment. We will need to first initialize a destination array with the required length and then use the <strong>copy</strong> method.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7549e18d9d4b1841188abff7bf605b9a/href">https://medium.com/media/7549e18d9d4b1841188abff7bf605b9a/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/090918076117fc9106f74ea282f814a2/href">https://medium.com/media/090918076117fc9106f74ea282f814a2/href</a></iframe><p>Note: The number of items copied to the destination is determined by the length of the destination array:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d83e8ae4abb43896919e292e2f9de262/href">https://medium.com/media/d83e8ae4abb43896919e292e2f9de262/href</a></iframe><p>Here only first 2 elements are copied because the length specified for variable b is only 2.</p><h3>Condition</h3><h4>If…else</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/87c1305e051723c171947265b7b1832e/href">https://medium.com/media/87c1305e051723c171947265b7b1832e/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0c08f28cf04807fc79dbe7e4002d55c7/href">https://medium.com/media/0c08f28cf04807fc79dbe7e4002d55c7/href</a></iframe><p>If a scope of a variable is within the if block only, then we can assign and check condition in the if condition itself as shown below:</p><pre>if name, ok := address[&quot;city&quot;]; ok {<br> // do something<br>}</pre><h4>Switch Case</h4><p>The execution of the switch case in Go is similar to Ruby i.e it only runs the selected case, not all the cases that follow. We use switch..case syntax in Go unlike case..when syntax in ruby.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/908b504d6b28b5f3b27d0af6f1778960/href">https://medium.com/media/908b504d6b28b5f3b27d0af6f1778960/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e3ed3079b4f82623cb8ee9f28dc8fac5/href">https://medium.com/media/e3ed3079b4f82623cb8ee9f28dc8fac5/href</a></iframe><h4>Type switches</h4><p>It is like a regular switch statement with the type specified for the switch case. We can learn more about it here: <a href="https://tour.golang.org/methods/16">https://tour.golang.org/methods/16</a></p><h3>Loop</h3><p>In Go, we only have for loop. However, we can use for loop to achieve different other kinds of loops as supported by Ruby which can be seen below:</p><h4>Normal For Loop</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8ac41a8e5cab2ac1b6f1b899beb91d02/href">https://medium.com/media/8ac41a8e5cab2ac1b6f1b899beb91d02/href</a></iframe><h4>While Loop</h4><p>There is no while keyword in Go. Instead for loop can be defined in a way to achieve the while loop as shown below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8f23dcfc4d67a7d1e3680b05d5bc8640/href">https://medium.com/media/8f23dcfc4d67a7d1e3680b05d5bc8640/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cf6b014081d06bb3b33c18a0bc93d11e/href">https://medium.com/media/cf6b014081d06bb3b33c18a0bc93d11e/href</a></iframe><h4>Infinite loop</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/59804137a0bbd4a1d977db06dd06b7ff/href">https://medium.com/media/59804137a0bbd4a1d977db06dd06b7ff/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b25bb0aefb32712b88725185f76f23fc/href">https://medium.com/media/b25bb0aefb32712b88725185f76f23fc/href</a></iframe><h4>Each Loop</h4><p>In Go, we have for loop with range which is similar to each in Ruby.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6f6c89d423aa6628fef4d851308cacbe/href">https://medium.com/media/6f6c89d423aa6628fef4d851308cacbe/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bdda1d2e5364527b3e4e1d8e02cf82c8/href">https://medium.com/media/bdda1d2e5364527b3e4e1d8e02cf82c8/href</a></iframe><h4>Each With Index</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fdd533d14d841f9134f6224678b7f51b/href">https://medium.com/media/fdd533d14d841f9134f6224678b7f51b/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dde106abbfebb302148a748afdaf0d66/href">https://medium.com/media/dde106abbfebb302148a748afdaf0d66/href</a></iframe><h3>Error Handling</h3><p>In ruby, we do the error handling using begin rescue block.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f79c72219a6828029400ccfb87fcc45d/href">https://medium.com/media/f79c72219a6828029400ccfb87fcc45d/href</a></iframe><p>In Go, there is a concept of Panic, Defer and Recover for raising error and rescue. However, It is extremely rare that we will need to handle panics in our code as these are generally handled by the framework and library code.</p><p>We can see in the example below, how an error is raised using Panic, and then recovered from this through the recover keyword which is inside the defer block. A <strong>defer statement</strong> defers the execution of a function until the surrounding function returns. So, in the example below, when there is panic the execution halts. Although the flow halts, but the defer statement gets executed. Thus, the recover statement inside the defer then gets executed which acts as a rescue block in Ruby.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3da2ab0a16f3e9614b91a5285246547d/href">https://medium.com/media/3da2ab0a16f3e9614b91a5285246547d/href</a></iframe><p>As mentioned earlier, we generally do not use Panic in the application code. Instead, we have an error interface that we use to check any error and take the action accordingly as shown in the example below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ddeda90bf4c599c423dc0944b9bc4e7e/href">https://medium.com/media/ddeda90bf4c599c423dc0944b9bc4e7e/href</a></iframe><h3>Defer</h3><p>It is similar to <strong>Ensure</strong> statement that we use in ruby.</p><p>Defer is used to ensure that a function call is performed later in a program’s execution, usually for purposes of cleanup. Some of the use cases of the defer are to <a href="https://gobyexample.com/defer">close the opened file</a>, close the HTTP connections etc.</p><h3>Functions</h3><p>In Ruby, we do not need to specify the return type as well as the argument type. While in go it is necessary to define the return type and also the argument type. Note that a return statement is required in Go else nothing will be returned whereas in ruby the return statement is not necessary. Ruby automatically returns the last line inside the function.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/45d95b77f34c7aa0ab3a4a2a8e53f5fa/href">https://medium.com/media/45d95b77f34c7aa0ab3a4a2a8e53f5fa/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c650ae3ad9fa9d5c04d52d6d41b56104/href">https://medium.com/media/c650ae3ad9fa9d5c04d52d6d41b56104/href</a></iframe><h3>Pointer</h3><p>In Ruby, we don’t have the concept of pointers. In Go, we have pointers which hold the memory address of the value. It is represented by the “<strong>*” </strong>operator<strong>. </strong>We have another operator &amp;, which gives the memory address of the value. It generates a pointer to its operand. The example below shows the referencing and dereferencing of a pointer.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/404963ee484086cd818a2397cfe66640/href">https://medium.com/media/404963ee484086cd818a2397cfe66640/href</a></iframe><h3>Object-Oriented programming</h3><p>Go is a light object-oriented programming language. It provides encapsulation and type member functions using struct but lacks inheritance. We can have functions attached to the struct. Once we define the struct, we can access variables and functions attached to the struct by creating an instance of the struct.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bf694a621d7f304db65069f18d989075/href">https://medium.com/media/bf694a621d7f304db65069f18d989075/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/75a13086e86555f7824d6fa6bac05eef/href">https://medium.com/media/75a13086e86555f7824d6fa6bac05eef/href</a></iframe><p>In the above example, we have defined a new type Festival with the help of struct. As we can see in the example we have created two functions “IsDashain” and “ToString” which is of type Festival. These functions are accessible through the instance of the Festival struct. In Go, these kinds of functions are called <strong>methods. </strong>Whereas in Ruby method and function are synonymous. Also, if we see the method definition, we are creating a method of festival pointer type. There are two important use-cases of making pointer receiver.</p><ol><li>When we need to modify the receiver, the receiver must be the pointer. In the above example, when the festival is “Dashain”, the pointer method changes the value of the festival which is now accessible to the main method.</li><li>If the request argument is large, having pointer receiver would be cheap and efficient as we will only be passing the address and not the large argument.</li></ol><p>Note: Go provides support for an <strong>interface</strong> which gives the feel of ruby inheritance/mixing and much more flexibility of OOP concepts.</p><h3>Public/Private methods and variables</h3><p>In Ruby, we define private methods by using keyword <strong>private. </strong>Anything written below <strong>private</strong> keyword is private. While in go defining private functions and variables can be achieved by defining methods/variables with a lowercase letter at the beginning of the method name.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1ecf8526888143ec25fff25963eadb1b/href">https://medium.com/media/1ecf8526888143ec25fff25963eadb1b/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a9ea53a5e609b7458e3b39b23529dbca/href">https://medium.com/media/a9ea53a5e609b7458e3b39b23529dbca/href</a></iframe><h3>JSON encoding/decoding:</h3><p>We use Marshal method of json for JSON encoding and Unmarshal method for JSON decoding in Go.</p><h4>JSON Encoding</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1efd44982197ba7850e673fb5e0a8f37/href">https://medium.com/media/1efd44982197ba7850e673fb5e0a8f37/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/82ab9c83ca146bc04b9432a4deaa6d56/href">https://medium.com/media/82ab9c83ca146bc04b9432a4deaa6d56/href</a></iframe><h4>JSON Decoding</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d9158814b0d5b65c54e8098a51d2cb3c/href">https://medium.com/media/d9158814b0d5b65c54e8098a51d2cb3c/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6dbdd9e58ba6ea7344cbdd809ac0c0c5/href">https://medium.com/media/6dbdd9e58ba6ea7344cbdd809ac0c0c5/href</a></iframe><p>Note: In the above example <strong>`json:”page”`</strong> command maps the <strong>page</strong> key of the input json to the <strong>Page</strong> attribute of the struct.</p><h3>Package:</h3><p>Packages in Go are similar to gems in Ruby. In Ruby, we install the gem with “<strong>gem install &lt;gem name&gt;”</strong>. While in GO, we install packages with “<strong>go get &lt;package path&gt;”.</strong></p><p>We also have different Go standard packages defined. Some of the commonly used packages are:</p><h4>fmt</h4><p>As per the naming, the package is used for formatting. This is a very handy package. In Ruby, we follow rubocop guidelines for the formatting. However, in Go, we need not worry about it. The fmt package takes care of it. After we work on the code, we can simply run:</p><pre>gofmt -w yourcode.go<br>//OR<br>go fmt path/to/your/package</pre><p>The code will be formatted automatically.</p><h4>log</h4><p>This package is similar to logger of Ruby. It defines a type <strong>Logger</strong> with methods for formatting output.</p><h4>net/http</h4><p>This is used for making HTTP requests. This is similar to net http in ruby.</p><h3>Concurrency in Go:</h3><p>Unlike in Ruby where we need to use different libraries such as celluloid for concurrency operations, Go language has built-in concurrency provided. We can simply run concurrent operations in go by using “<strong>go</strong>” keyword in front of the operation. As shown in the example below, we are executing a function with parameter “goroutine” concurrently with the main function by simply writing <strong>“go” </strong>keyword in front of the function call.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9e6414ba776cebc9da2951cf11a7acdb/href">https://medium.com/media/9e6414ba776cebc9da2951cf11a7acdb/href</a></iframe><p>There is another concept called <strong>Channels </strong>which is used for the communication between the two goroutines. With channel, we can send and receive values between the goroutines.</p><h3>Explore more on Go:</h3><ol><li><a href="https://golang.org/doc/effective_go.html">https://golang.org/doc/effective_go.html</a></li><li><a href="https://play.golang.org/">https://play.golang.org/</a></li><li><a href="https://tour.golang.org/welcome/1">https://tour.golang.org</a></li><li><a href="https://gobyexample.com/">https://gobyexample.com/</a></li><li><a href="https://www.safaribooksonline.com/videos/mastering-go-programming/9781786468239">https://www.safaribooksonline.com/videos/mastering-go-programming/9781786468239</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c0a0ce19e367" width="1" height="1" alt=""><hr><p><a href="https://medium.com/devnetwork/golang-for-ruby-developers-c0a0ce19e367">GoLang for Ruby developers</a> was originally published in <a href="https://medium.com/devnetwork">Devnetwork</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>