Why Golang is the future? Part 1
Because it is made by Google.
Of course, this is not the only reason. Google is pretty good at creating products with maximum focus on efficiency and user-friendliness, whatever they are. And people genuinely love Google products. It can only mean that we really need software development breakthroughs, even if we don’t know about it yet. This is what happened with Golang.
Firstly, let’s answer this simple question: why is Golang got so popular?
- It is convenient, fast, and secure to write code with Golang, and it provides cross-platform support, which simply can’t be bad.
- Google cares about the user. They created tons of free official guides and made Golang open-source, so that now there’s a huge collection of add-ons and packages.
- Golang has cloud infrastructure. Now you say “Come on, enough talking about clouds, nobody cares”, and I’ll answer “Yes, nobody cares because you’ve got used to this luxury!”. Go is a part of Google Cloud, Dropbox, MS Azure, and AWS. All-in-one super-capable multi-purpose coding monster. Isn’t it fantastic?
- Google has money. It doesn’t mean you’ll earn money from Google by using Golang, but it does mean this technology has a regular financing and improvement.
Before we answer the question: “Why Go is the future?”, it is important to understand why it was necessary to create another programming language when we already have so many of them.
Let’s talk history
Go was developed by several talented engineers: Ken Thompson, known to you as a developer of UNIX OS and one of the co-authors of the UTF-8 encoding; Rob Pike, who also participated in the development of UTF-8 and two operating systems: Plan9 and Inferno; Robert Griesemer, who worked on Java HotSpot, Sawzall, and distribution systems in Google. The first version of Go language was available to the public in 2009, and version 1.0 was released in 2012. So young and so popular.
In the early 2000’s, the number of physical cores in processors significantly increased, while many languages which were designed in 90’s, were based on single-core systems. Go was developed to write efficient, high-loaded programs and services that can use resources of multi-core systems.
The thing is, most programming languages, such as C#, Java, Python and others, support multi-threading, just like Go. Then why Go is a competitor?
Let’s talk processors and memories
Now, we’ll look at how the request is implemented in a modern web server. The speed of a modern processor is much greater than the speed of RAM. In order to somehow compensate this, we have fast and small memory — cache, which is located on the same chip. RAM starts working right after the cache because it’s much slower. For example, it may take up to 100 nanoseconds to gain access from the processor core to the main memory. This is quite a lot of time, given a number of operations that a modern processor performs. So the following question arises: What happens in the processor during the execution of tasks?
The processor recognizes several entities, which it works with: a thread of execution, a process, and a thread. The thread of execution is the smallest unit of processing, the execution of which can be assigned by the operating system kernel. A process is a currently running program. A thread is a lighter essence than a process and it has access to process memory. That is, you can reuse some connections, for example, connections with the database.
A thread takes less memory than a process but processor also sees it as system operation. Due to this fact, the processor can detect and process a higher number of threads, respectively — it can process more requests per time unit.
The processor performs operations sequentially, it does not know anything about other programs. A task scheduler deals with switching from one program to another. For this action, it takes one thread and saves its condition. Then it takes the state of another thread, loads it into the processor, and starts this process. What does the memory have to do with it? The thing is, when tasks are switching, you may need to have access to the RAM. Since there is no data cache for this process, it will be loaded. In modern processors, up to one microsecond is spent on this action, which is quite a lot.
When the context is switching and you increase the number of programs that run on your computer, everything starts to work slower. Each action takes some memory and time. But what does it have to do with Golang?
Let’s talk purpose
Efficiency is the second name of Golang, it’s the core aim. Go was generally designed to handle a large number of competitive but completely independent requests which your program receives simultaneously.
The second aim of Go was to increase the efficiency of the programmer. Go has a very simple syntax which allows you to write programs easily, quickly understanding the code. Because programs usually live much longer than we think. For these purposes Go created a standard code format and made a built-in IDE tool for automated formatting. Go is very fast to compile. This means, if you need to check whether the program works, you won’t have to wait 20 minutes until it’s assembled. It’s very convenient to work with dependencies when writing on Go. All code lies in one place. When you need to build it, all code turns into a static binary, which allows it not to depend on any external packages and this prevents any conflicts with other programs.
Let’s talk areas
According to the Golang survey which was conducted in 2016, Go is mainly used for web development, that is, any web services, monitoring systems, and various system utilities.
Go is not the best choice if you need very tight control over the memory and cannot afford any pauses in software operation. Because Go is a language with a “garbage collector”.
Of course, there are no stop-the-world pauses which hang everything up for a long time, but there are some. Therefore, it’s difficult to use Golang for building real-time systems.
Also, if you are working with embedded devices, IoT, wearables, which usually have tiny memories — then Go is not be the best choice for those kinds of projects.
Golang is a perfect choice for web. Today, applications use a number of external services: databases, caches, message queues. This is why developers often build applications on microservices architecture using asynchronous Input / Output. Thanks to that, application can interact with any number of services without blocking web requests. Also, Golang is not tied to platforms but succeeds in writing APIs and supports JSON format pretty well.
Web developers with extensive experience appreciate these advantages of Go and wait for 2019th improvements and breakthroughs from Google team even more.
The second part is here: