You Better Get Going with Go

Well, this is basically my story too. I left Node.js as well, and now I use the Go Language (Golang, Go) as my backend technology of choice. Although Node.js will always have a warm place in my heart, if you are looking for the best backend technology that is out there, I fully recommend Golang. Let me tell you why.

“I think Node (.js) is not the best system to build a massive server web. I would use Go for that. And honestly, that’s the reason why I left Node. It was the realization that: oh, actually, this is not the best server-side system ever.” (HS, 2017) This quote is by Ryan Dahl the author of Node.js.

But, a programming language should be perfect—both efficient and simple, right? Go is both, and a lot more. Let me elaborate a little further on why that is.

The motivation behind the creation of Go was that currently, there are many programming languages available. Each has its own pros and cons. There are some languages that are efficient, but not simple, like C and C++. And, on the other hand, there are simpler languages that are less efficient, like JS and Python.

  • It does not have objects, but it supports structures (structs) and any type can have a method.
  • It does not support inheritance, but does support compositions and interfaces.
  • You can have a pointer to a variable, but at same time, you don’t have to worry about referring to its methods.
  • It’s statically typed, but it’s non-strict because of the type inference.
  • Its package-based code management reduces the number of code lines.
  • And last but not least, Go has a simple concurrent model.

Let’s dig into some examples of the simplicity, but awesomeness of Go.

Go syntax is something between C and Python with advantages from both languages. It has a garbage collector that is very useful.

  • By starting a Goroutine, it supports concurrent routing:

o    go runConcurrently()

  • Swapping between variables is simple:
    • b, a = a, b
  • It allows you to import a package directly from GitHub or any other source manager:

o    import “github.com/pkg/errors”

Go’s runtime performance is similar to C++ and C, making its performance quite notable.

  • Allows you to refer to a method of instance of some type, no matter if it’s a pointer or the actual instance:
    • instance.method()

Thanks to the Go dependency model and its memory management, the compilation is very fast when compared to low-level languages, and even more so with high-level languages.

In the context of scaling, Go is much faster than popular competitors thanks to the Goroutines model as you can see in the figure below.

Go is an open source language with wide adoption and a fast-growing community. On the web, you can find lots of free and useful packages and many Q&As, FAQs, Tutorials, etc.

When comparing Goroutines to Java threads, Goroutine threads consume ~2KB, while Java threads consume ~1MB.

According to 2019 stack-overflow survey among developers, Go is one of the most popular languages. 8.2% of the survey respondents are programming in it, and 67.9% of the respondents mentioned Go as their most loved, dreaded, and wanted language. Go scored the highest rank (93% of the respondents) as a preferred language in a 2019 survey by Golang within Go developers, and as you can see in the Figure below, Go is growing in popularity.

Looking to quickly increase your knowledge of Golang security? Check out our Intro to Go Language guide!

In addition to that, Go is super easy to learn. Because of its friendly syntax and the great “Tour of Go” (that takes about two days to complete and covers all the basics you’ll need to get started programming in Go), after completing the tour, you will feel very confident with the language. When you start using the language, coding with it will become pretty easy overall. And after about two weeks of using it, it will likely become your preferred/native language.

So, hear this Gopher out!

Reference

You Better Get Going with Go.

This post was first first published on Blog – Checkmarx’s website by Stephen Gates. You can view it by clicking here