Why 2017 you have to learn Go (multicore, networking, multiplayer collaboration, simple non-oo, no annotations, Native, garbage Collection, code elegance), with two reviews

Source: Internet
Author: User
Tags knowledge base

Why learn to go

Go is the future service-side language-? Tobias Lütke, Shopify. In the past few years, Golang has gradually become popular. What can be more crazy than a new language for yards farmers? So I started to study for a while Golang, here I will tell you why you should also learn this new language. I won't tell you how to write Hello World in this article. I want to analyze the current stage of computer hardware software to explain why we need a new language like go?

Hardware Limitations

Moore's law is failing. The first Pentium 4 processor with a 3.0GHz clock speed was launched by Intel in 2004. Today, my Mackbook Pro 2016 has a CPU clock speed of 2.9GHz. You can see that the CPU processing power has not progressed much in the last decade. You can see this in the chart below.

As you can see from the chart above, single-threaded performance and processor frequency have remained stable for the last 10 years. If you think adding more transistors is the solution, then you're wrong. This is because some of the quantum properties on the smaller scales begin to appear (such as tunnels, because it actually uses more transistors than ever (why?). ) and the cost/performance of the added transistor is declining. So manufacturers are starting to add more and more cores to the processor. Now we have four-core and eight-core CPUs available. We've also introduced Hyper-threading. Additional caches are added to the processor to improve performance. But these solutions also have their limitations. We cannot add more caches to the processor to improve performance because the cache has a physical limit: the larger the cache, the slower the cache. Adding more cores to the processor also has a cost. In addition, this cannot be infinitely extended. These multicore processors can run multiple threads at the same time and bring concurrency on paper. We will discuss this issue later. Therefore, if we cannot rely entirely on hardware improvements to improve performance, more efficient software is also a means for us to consider. Unfortunately, modern programming languages are not efficient.

Go has goroutines!!

As mentioned above, hardware manufacturers are adding more and more cores to the processor to improve performance. All datacenters using these processors will have a significant increase in the number of cores over the next few years. More importantly, today's applications use multiple microservices to maintain database connectivity, Message Queuing, and caching. As a result, the software and programming languages we develop should easily support concurrency, and they should easily scale as the number of cores increases. However, most modern programming languages (such as Java,python, etc.) were invented in the 90 's single-threaded environment. Of course this does not mean that they do not support multithreading (the translator's word Python does not support multithreading). Most programming languages support multithreading. The real problem comes from concurrent execution and the lock, race conditions, and deadlocks. These things make it difficult to create multithreaded applications in these languages. For example, creating a new thread in Java consumes approximately 1MB of memory heap size. Eventually if you create thousands of threads, this will put a lot of pressure on the heap memory and will be killed by the operating system due to low memory. Also, if you want to communicate between two or more threads, it is more difficult. On the other hand, when Go was released in 2009, multicore processors have become popular. That's why Golang is the first priority in concurrency. Go uses goroutines instead of threads. The new Goroutine only uses nearly 2KB of memory, and you can create millions of goroutine.

Of course there are other benefits:

    • has an extensible staging heap. This means that they use more memory only when they need it.

    • Goroutines boot time is faster than thread.

    • The Goroutines has a built-in primitive to communicate securely between them (channel).

    • Goroutines allows you to avoid using mutexes when sharing data structures.

    • Additionally, the Goroutines and OS threads are not 1:1 mapped. A single goroutine can run on multiple threads. The goroutine is reused in a small number of OS threads.

The above points make go very powerful and can keep the code elegant (like Earlang) while processing concurrency (such as Java, C, and C + +).

Go runs directly on the hardware

One of the biggest benefits of using C, C + + is their performance is stronger than other modern high-level languages such as Java/python. Because C + + + is compiled and not interpreted as execution. When you build an application using Java or other JVM-based languages, it compiles the code into bytecode, and at execution time, the JVM interprets the bytecode and translates it into binary code that the processor can understand.

C, C does not execute on the VM, removes a step from the execution cycle, and improves performance. They compile the code directly into binary code.

However, it is too painful to release and allocate memory in C + +. Even though most programming languages can use the garbage collector or the reference counting algorithm to handle object assignment and deletion. Go also has the benefits mentioned above. Go is a low-level language such as C/s + + and a compiled language. This means that its performance is almost closer to the low-level language. And go also uses garbage collection to allocate and free memory. So there's no need for malloc and free!!!.

Go code is easy to maintain

Go has a very neat and clean grammar. The designer of Go takes this into account when creating the language. Because Google has a very large code base, thousands of developers are using the same code base, the code should be easy for other developers to understand. This makes the code easy to maintain and modify. Go has deliberately removed many of the features of modern OOP languages.

    • No class. Go is only a struct, not a class.

    • Inheritance is not supported. This makes the code easy to modify. In other languages, such as Java/python, if the ABC class inherits class XYZ, and some changes are made in class XYZ, this can have some side effects in other classes that inherit XYZ. By removing inheritance, go makes it easy to understand the code (because there is no superclass).

    • No constructors.

    • No annotations (annotation).

    • No generics (generics).

    • No exception.

The differences above make go very different from other languages. Of course you may not like some of the above points. However, in the absence of these features, all you need to do is write more than 2-3 lines of code. However, this will make your code more concise and understandable.

The show go is almost as efficient as C + +, while keeping the code syntax simple, like Ruby,python. This is a winning situation for both humans and machines! Unlike other new languages (like Swift), Go's syntax is very stable. It has remained unchanged since the first public release of version 1.0 in 2012. This makes it backwards compatible.

The back of Go is Google
    • Although this is not a direct technical advantage. But go is designed and supported by Google. Google has one of the largest cloud infrastructures in the world and can scale massively. Go is designed by Google to address the scalability issues they need. These are also the problems you will face when creating your own services.

    • Go is also used by some big companies, such as ADOBE,BBC,IBM, Intel, and so on.

Conclusion
    • Even though go is very different from other object-oriented languages, it also provides you with high performance (such as C + +), super-easy concurrency (such as Java), and concise code (such as Python/perl).

    • If you don't have any plans to learn go, I would say that software developers need to write ultra-efficient code. Developers need to understand the hardware and optimize the program accordingly. Optimize software to run on cheaper and slower hardware, such as IoT devices, to improve the end-user experience.

Manuscripts: Go China

Http://www.oschina.net/news/80938/why-2017-you-have-to-learn-go

To tell you the truth, how many languages you've learned to go, and how much you feel excited about the fur. On performance, GO than Erlang, Rust, Nim, Crystal difference far, on faster than Nodejs even PHP 7 poor 108,000, especially Nodejs not only HTML5 back end Dragon, now NW and Electron make desktop application can JS Dragon. Ecology is 108,000 miles worse than Java, Python, and Nodejs. On grammar, even C + + is inferior, the other does not have to compare. Finally, even TypeScript's static compilation syntax is hundreds of times times stronger than GO. GO is a person who has no language design concept, after all, C language He was only a participant, not the designer. Add: Go's Goroutine is Java's Nio,nodejs libuv and async await, even C # 's async await is this concept, Nim's async await and C + + 's future It's all a thing. Go has no other language is not.

See a lot of people spray Golang, talk about my opinion, recommend to use the Golang development project in person before commenting. I have personally developed several golang projects, feeling no worse than other languages and efficient enough.
Golang in simplicity, new life, this is destined to be better than other languages, because the history of other languages left a lot of problems. For example, PHP developed a web to consider a variety of frameworks (I wrote my own framework, the development efficiency is not as fast as expected), and the Golang native HTTP library can solve most of the application scenarios.
Many advanced, excellent products are from excellent developers, because this part of the people will continue to try new things, and constantly update their knowledge base, rather than behind closed doors, the rest of their laurels.
For example, the development of Gogs, the basic can replace the gitlab;docker will not have to say more.
Finally, there is no difference in programming language, the key to see people.

Why 2017 you have to learn Go (multicore, networking, multiplayer collaboration, simple non-oo, no annotations, Native, garbage Collection, code elegance), with two reviews

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.