The programmer is bald again: Why start learning Google Go language?

"Go will become the server language of the future."-Tobias Lütke, Shopify

In the past few years, new programming languages ​​have increased: Go or GoLang. Nothing can make developers crazy instead of a new programming language, right? So, I started to learn Go 4 to 5 months ago. Here, I will tell you why you should also learn this new language. I want to explain the current stage of computer hardware-software and why do we need a new language like Go? Because if there is no problem, then we don't need a solution, right?

 

Hardware limitations:

Moore's Law is cold.

Intel introduced the first Pentium 4 processor with a 3.0GHz clock speed in 2004. Today, the clock speed of my Mackbook Pro 2016 is 2.9GHz. Therefore, for almost ten years, the original processing capacity has not improved much. You can see the comparison of increased processing power and time in the figure below.

So, for solutions to the above problems, manufacturers are beginning to add more and more cores to processors. Today we have quad-core and eight-core CPUs available.

We also introduced hyperthreading. Added more cache to the processor to improve performance.

 

But the above solution also has its own limitations. We cannot add more and more caches to the processor to improve performance, because caches have physical limitations: the larger the cache, the slower the speed achieved. Adding more cores to the processor also has its cost. Moreover, this cannot scale indefinitely. These multi-core processors can run multiple threads simultaneously, which brings concurrency to the image.

Therefore, if we cannot rely on hardware improvements, the only way out is software that improves performance. Unfortunately, modern programming languages ​​are not efficient.

Go has goroutines!!

As mentioned above, hardware manufacturers are adding more and more cores to processors to improve performance. All data centers run on these processors, and we expect the number of cores to increase in the next few years. More importantly, today's applications use multiple microservices to maintain database connections, message queues, and maintain caches. Therefore, the software and programming languages ​​we develop should be able to easily support concurrency, and they should be scalable as the number of cores increases.

 

However, most modern programming languages ​​(such as Java, Python, etc.) are derived from single-threaded environments in the 90s. Most programming languages ​​support multithreading. But the real problems are concurrent execution, thread locking, race conditions and deadlocks. These things make it difficult to create multithreaded applications on these languages.

For example, creating a new thread in Java is not memory efficient. Since each thread consumes about 1MB of memory heap size, and eventually if you start spinning thousands of threads, they will put huge pressure on the heap and cause shutdown due to insufficient memory. In addition, it is very difficult to communicate between two or more threads.

On the other hand, Go was released in 2009, when multi-core processors were already on the market. This is why Go is built on the basis of maintaining concurrency. Go has goroutines instead of threads. They consume about 2KB of memory from the heap. Therefore, you can spin millions of goroutines at any time.

Other benefits are:

Goroutines have a segmented stack that can grow. This means that they will only use more memory when needed.

Goroutines have faster startup time than threads.

Goroutines have built-in primitives that can communicate securely between them (channels).

Goroutines allow you to avoid using mutexes when sharing data structures.

In addition, there is no 1:1 mapping between goroutines and OS threads. A single goroutine can run on multiple threads. Goroutines are multiplexed into a small number of OS threads.

Go runs directly on the underlying hardware.

Compared with other modern high-level languages ​​(such as Java/Python), the biggest advantage of using C and C++ is their performance. Because C/C++ is compiled rather than interpreted.

The processor understands the binary file. Usually, when compiling a project using Java or other JVM-based languages ​​to build an application, it will compile human-readable code into byte code, which can be understood by the JVM or other virtual machines running on the underlying operating system. When executed, the VM interprets these bytecodes and converts them into binary files that the processor can understand.

 

On the other hand, C/C++ will not execute on the VM, and remove one step from the execution cycle and improve performance. It directly compiles human readable code into binary files.

However, releasing and assigning variables in these languages ​​is a huge pain. Although most programming languages ​​use garbage collectors or reference counting algorithms to handle object allocation and deletion.

Go brings the best in the world. For low-level languages ​​like C/C++, Go is a compiled language. This means that performance is almost close to lower level languages. It also uses garbage collection to allocate and delete objects. So, there are no more malloc() and free() statements! Cool! ! !

Code written in Go is easy to maintain

I tell you one thing. Go does not have the crazy programming syntax of other languages. Its syntax is very neat.

The designers of Google Go took this into consideration when creating the language. Since Google has a very large code base, thousands of developers are working on the same code base, so the code should be easy to understand for other developers, and one piece of code should have minimal impact on another part of the code side effect. This will make the code easy to maintain and easy to modify.

 

The above changes make Go very different from other languages, and it makes programming in Go different from other languages. You may not like some of the above points. However, without the aforementioned features, you cannot code the application. All you have to do is write 2-3 more lines. But on the positive side, it will make your code clearer and add more clarity to your code.

Go is backed by Google support

I know this is not a direct technical advantage. However, Go is designed and supported by Google. Google has one of the largest cloud infrastructures in the world and is huge. Go was designed by Google to solve the problem of supporting scalability and effectiveness. These are the same problems you will face when creating your own server.

 

What's more, Go is also used by some big companies, such as Adobe, BBC, IBM, Intel.

in conclusion:

Although Go is very different from other object-oriented languages, it is still the same beast. Go provides you with high performance, such as C/C++, super-efficient concurrent processing, such as Java, and the fun of Python/Perl and other code.

If you don't have any plans to learn Go, I would still say that hardware limitations will put pressure on us, and software developers have to write super-efficient code. Developers need to understand the hardware and optimize their programs accordingly. Optimized software can run on cheaper and slower hardware (such as IoT devices) and has a greater overall impact on the overall user experience.

Code code is not as good as DIY artificial intelligence, so what is Google AIY?

AIY is a combination of DIY (do it yourself) and AI (artificial intelligence) created by Google. And these keywords basically tell you exactly the purpose of these toolkits: do it yourself artificial intelligence. Google AIY currently offers two different packages.

According to reports, the Google AIY series of development kits have arrived in Hong Kong for sale, and the prices are HK$706 and HK$392. Interested developers can pay attention to the Hong Kong online store of Google AIY series development kits-GravitylinkStore. Users can provide their own applications or even use Google's TensorFlow machine learning software to train their models to make them more effective.

Guess you like

Origin blog.csdn.net/gravitylink/article/details/89025287