Go — A quick guide for getting started

Madhavan Nagarajan
Level Up Coding
Published in
6 min readApr 13, 2020

--

Go was created as an effort to give a single language that mixed efficient compilation, efficient execution, and ease of programming. In the last few years, Go’s rise in fame has demonstrated that it has filled a need in the software development society. Here, we’re going to take a look at Go from a high level, and we’ll answer the following questions.

  1. What is “Go”?
  2. Why you might have to choose “Go”?
  3. What is it like to program in “Go”?

Now that we have our roadmap, let’s start diving in by answering the question, what is Go?

What is Go:

Go is an open-source programming language that makes it easy to build simple, reliable, and efficient software.

Go is just another language in the world of computer programming. But this might kindle a question in your mind why do we need another language when there are already a bunch of well established and powerful languages out there?

Most of the languages that are out there are created at a period with no clue about the modern age problems that we are trying to solve. All those languages have to be evolved over time to adapt themselves to the current age.
The inception for a new programming language is lighted in the mind of the designers in the google to find ideal language for the problems that we are facing now and also to strike a balance between the efficiency of the language versus the convenience.

Go has become very popular due to its ability to combine the performance and type safety of venerable languages such as Java and C++ with the pleasant developer ergonomics and near-instant compile times of scripting languages such as Python and JavaScript.

The main goal of creating Go was to combine the best features of other programming languages:

  • Ease of use together with state-of-the-art productivity
  • High-level efficiency along with static typing
  • Advanced performance for networking and the full use of multi-core power

Why choose GO

The philosophy and value of the language

The first thing that has to be highlighted is simplicity. throughout the language be it the design, syntax, the features that are included and that are excluded are all about the simplicity.

The next best thing to mention here is the out-of-box experience. Many traditional languages out there needs are a lot of scaffolding before we get the basic service out of it, Go on the other hand focuses on the true out-of-box experience. The standard library of Go is not just extensive but also intended to provide the core and most powerful concepts that are required to build significant applications. This also includes the packages for compressing, a well-equipped test suite, http/net package for web application etc. All this is to make overall user experience hassle-free.

The next major thing to mention here is the simplified cross-platform deployment. Cross-compiling works by setting the required environment variables that specify the target operating system and architecture. We use the variable GOOS for the target operating system, and GOARCH for the target architecture. Just by changing the environment variables, we can get the code compiled to the desired operating system.

The bigger lead of Go over other languages is its awareness of the network and built-in concurrency. The problem with traditional languages like java, c++is they acquired the skill like network and concurrency at later part of their development. They were never designed with network and concurrency in mind. So when Go was designed, that was one of the considerations that the design team made and really wanted to make sure that they had nailed down. So how did they do that? Well, from a network-aware standpoint, we see that in the core Standard Library, we have the net and the net/HTTP packages. From a concurrency standpoint, we have goroutines, which are lightweight threads that allow for massive concurrency to be managed in your application. And in order to handle communication between those multiple concurrent tasks that are going on, Go has channels built-in, which support the implementation of communicating sequential processes, or CSP, and that allows us to have messages passed between our concurrent goroutines in a thread-safe way.

Primary use cases of Go:

  1. web services and web applications — This was one of the primary considerations that the team within Google was thinking about as they were designing this language, and they are really able to take advantage of that network and concurrent aware nature of the Go language.
  2. DevOps space — if you’re familiar with programs such as Docker and Kubernetes, those are actually written in the Go, which has proven itself to be a very powerful replacement to C in creating these very low-level system tools.
  3. Go has also proven itself to be a valuable tool in the machine learning space, and we see a lot of application developers that had been using Python or R, are starting to turn to Go because of the high-performance nature and builtin concurrency that it offers

What it is like to use Go:

let’s see a quick spin

package main
import (
"fmt"
"net/http"
)
func main() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello, you've requested: %s\n", r.URL.Path)
})
http.ListenAndServe(":3000", nil)
}

the above program is the basic “hello world” for creating web services in go, you could clearly see that we only relied on the core standard library to create this. Just by writing 5 lines of code we were able to spin a server with a powerful language. This is the level of simplicity go is designed with, by simplicity I mean the ultimate level of sophistication.

Conclusion:

We saw that simplicity is a core concept in Go. So even if there are powerful language features that could really make Go applications much stronger, sometimes the complexity that those features add to the language are such and add such a burden to the Go language itself, so the compiler and the toolchains, as well as the editor environments and the cognitive load, the ability to learn the language, that the decision has been made to actually leave some of those more powerful features out for the sake of simplicity. Batteries included tooling is another key philosophy and value. Also, a key philosophy and value of Go is backward compatibility. So while it’s not guaranteed that backward compatibility will always be preserved, there is a very, very strict set of criteria that are used to determine if backward compatibility should be broke; otherwise, the backward compatibility is remarkably stable.

Every programming language is more than just a collection of syntax, and compilers, and libraries. In addition to the mechanical nature of the language, it’s important to understand the philosophy and values of the people that are building that language, building the community, to make sure that their philosophy and values are really meshing and aligning with yours so that your use cases are more likely to be solved effectively.

Thank you for reading my article. If you think its useful, please do share, clap, comment ✌😊

--

--