##This tutorial Operating environment: Windows 7 system, GO version 1.18, Dell G3 computer. Each programming language has its own advantages and disadvantages, and Go is no exception. Let’s list the “advantages” and disadvantages of Go. "Disadvantages":Disadvantages of the go language: 1. "Performance disadvantage" caused by the choice of technical route. Go is a GC programming language. In some situations where performance is super sensitive, you still have to be cautious when choosing Go. 2. "Single expression method" and explicit error handling are a bit "outdated". 3. The smallest version chooses MVS, which deviates from the mainstream. 4. The Go core team has full control over language evolution, and it will not be approved by the majority of the community. Being adopted and added to the Go language has resulted in a disadvantage in the community, and there is a "crack" between the Go community and the Go core team. 5. Weak functionality.
Advantages of Go
1. Simple and easy to learnThe Go language has a simple syntax, which includes elements similar to C The syntax of the language. If the reader has already mastered two to three programming languages, it only takes a few days to learn the Go language. Even a new developer can write a high-performance Go language in a few weeks. Language program. 2. Free and efficientThe compilation speed of Go language is significantly better than that of Java and C. It also has an operating efficiency close to C language and a development efficiency close to PHP. It can be said that Go language It perfectly integrates operating efficiency and development efficiency. At the same time, Go language also supports all current programming paradigms, including procedural programming, object-oriented programming, interface-oriented programming, and functional programming. Developers Can be freely combined according to needs. 3. Powerful standard libraryThe standard library in Go is very stable and rich and diverse, including network, system, encryption, encoding, graphics and other aspects. Especially It is a very practical network and system library that allows developers to almost not rely on third-party libraries when developing large programs. 4. Easy deploymentNo need to use a virtual machine, Go language The code can be directly output as a binary executable file. Moreover, the Go language has its own linker and does not rely on the compiler and linker provided by any system. Therefore, the compiled binary executable file can run in almost any system environment. 5. Native support for concurrencyGo language is a very efficient language that natively supports concurrency from the language layer and is very simple to use. The concurrency of Go language is based on Goroutine, which is similar to threads , but not threads, is a lightweight thread-oriented method of Go language. The cost of creating Goroutine is very low, only a few thousand bytes of additional memory. Usually an ordinary desktop host runs hundreds of One thread will be overloaded, but the same host can run thousands or even tens of thousands of Goroutines. Communication between Goroutines can be achieved through channels. Goroutines and channel-based concurrency methods can maximize the use of CPU resources. 6. Strong stabilityGo language has powerful compilation checks, strict coding standards and strong stability. In addition, Go language also provides software life cycle (such as development, testing , deployment, maintenance, etc.), such as: go tool, go fmt, go test, etc. 7. Garbage collectionWhen using Go language for development, in terms of memory, developers only need to pay attention to the application of memory, and do not need to worry about the release of memory, because the Go language has built-in Runtime is used to automatically manage it. Although GC (Garbage Collection, garbage collection mechanism) is not perfect at present, it is enough to cope with most situations encountered during development, allowing developers to focus more on business. At the same time, Go language also allows developers to This work is optimized.Go's disadvantages
1. "Performance disadvantage" caused by technical route selectionAs we all know, Go is full of garbage It is a recycling programming language, so no matter how short Go's STW (Stop The World) time is and how small the GC delay is, it still belongs to the GC class programming language and belongs to the same camp as Java and C#. At the same time, it is naturally related to C, A clear line is drawn between C and programming languages like Rust that manually manage memory and do not have the burden of runtime GC. Although the original intention of the Go language is to become a system-level programming language, although Go's runtime performance can meet the needs of 99.99% of occasions, although Baidu's trillions of traffic [forwarding engine BFE], time series database [influxdb], and distributed relational database [ TiDB] and other performance-sensitive projects have chosen to be implemented in Go, but it cannot be denied that in some extremely performance-sensitive situations, you still have to be cautious when choosing Go. 2 The "expression disadvantage" brought about by adhering to one's own design philosophy1) "Single" expression methodMany developers who switch from other languages to the Go camp People complain that Go has too few tricks and not many routines. The reason why Go shows "expression disadvantage" stems from a principle in its design philosophy: "It advocates that there is only one or a few ways to write a thing." This principle does not meet the psychological needs of some developers to show off their skills, so Go is criticized as a language only used by programmers with mediocre qualifications.[Go 1.18 will add generics (type parameters)], which can be regarded as a "compensation" for such "disadvantages". However, for those of us Gophers who have long recognized Go's values and design philosophy, we are very worried that [generics], which has greatly improved Go's expressive capabilities, will become a "breeding ground" for tricks and tricks.
2) "Outdated" explicit error handling
Since the day it was born, the Go language has not provided an exception-based structure like mainstream programming languages such as C, Java, and Python. Instead of try-catch-finally error handling mechanism, Go designers believe that coupling exceptions to program control structures will lead to code confusion. Go provides a simple error handling mechanism based on error value comparison, which "forces" every Go developer to explicitly pay attention to and handle each error. Code with explicit error handling will be more robust. It will also give Go developers more confidence in the code. However, the persistence of this design philosophy has been ridiculed by many developers from other languages as "outdated" and called "an ancient mechanism from half a century ago." (Author's note: The error handling mechanism used when the C language was born in the 1970s)
The Go development team has also been "shaken". The Go development team has released multiple versions after the release of the Go2 plan [Go Draft new mechanism for error handling]. The Go community has also had long discussions and even "quarrels" on this issue. Well-known Gopher Dave Cheney spoke out, Rob Pike spoke out, and William Kennedy, a well-known Go trainer and one of the co-authors of "Go Language Practical Combat" After the Go team's try proposal was announced, they published an open letter to the Go community opposing the try plan. In the end, the group that insisted on the Go design philosophy gained the upper hand, and the try proposal was rejected and was not included in [Go 1.13 version]!
3. "Niche Disadvantages" that deviate from the mainstream
Go's early design of the package dependency management mechanism does have quite a few "flaws", which stems from the large internal code warehouse within Google and the The impact of trunk's development model. The Go language outside of Google has heard voices from different aspects. The Go package management mechanism has been unable to meet the needs of the community for a long time. As a result, there have been attempts to improve package dependency management such as [vendor mechanism] and [dep].
At the beginning of 2018, just when most gophers thought that dep would be "naturally" upgraded to part of the official go tool chain, Russ Cox, the technical leader of the Go core team and one of the early members of the Go core team He published [seven articles] on his personal blog, systematically expounding the Go team’s technical solution to “package dependency management”: [vgo], the predecessor of go module.
The main ideas of vgo include: Semantic Import Versioning and Minimal Version Selection. These are contrary to the rules of package dependency management of current mainstream programming languages, especially [Minimal Version Choose (MVS)], which is a new approach and deviates from the mainstream!
4. The "community disadvantage" caused by the Go core team's "democratic centralism"
is different from the Rust team's extensive adoption of community suggestions to "increase language features", Go is like another extreme : The Go core team has full control over the evolution of the language. Unless the majority of the community agrees, it will definitely be adopted and added to the Go language. I jokingly call it "democratic centralism", that is, the real voting power actually lies in Go. The core team represents a small number of people in the community.
The dispute between dep and vgo in early 2018 is a typical manifestation of this "disadvantage". The dep project that the community has worked hard to build for more than a year has been "squeezed out" by vgo, which was designed by Russ Cox and a few other people who spent some time focusing on it. The position of the Go package dependency management tool standard has become a "stepping stone" for the success of Go modules. . Even if it turns out that the Go team's decision to use go modules is correct, the "rift" between the Go community and the Go core team does exist, so that in the past two years, the Go core team has worked hard to improve relations with the Go community. relationship, standardizing and transparentizing the process of proposing, reviewing and accepting Go proposals.
5. After the failure of the all-out attack, the "functional weakness" caused by the failure of expectations
After the release of Go 1.5, Go has attracted much attention due to the significant reduction in bootstrapping and GC delays. It gradually increased until it won the TIOBE Programming Language of the Year for the second time in early 2017, which made the Go language somewhat "inflated". Even fanatical Go advocates once hoped that Go would dominate the world: not only firmly controlling its own cloud native market , to occupy the enterprise-level market of Java, we must also defeat existing opponents on the terminal (android. ios) and front-end (js).
Some people may think my above statements are ridiculous, but they are not groundless. The Go language has really made great achievements in terminal and front-end aspects. Anyone who knows the history of Go knows that the Go team once had full-time developers participating in the [gomobile project](, which aims to build the Go technology stack on Android and iOS. , to achieve the purpose of writing terminal applications in Go language.
In terms of front-end, [gopherjs project] can compile go code into js code and run it in major browsers. Later, the author of gopherjs helped the go project Natively supports webassembly, and supports compiling go into webassembly and running it in the browser.
However, the above attempts ultimately failed to "succeed". The current situation is that in the field of terminal and front-end applications, very few people use Go coding. So Go gradually calmed down and returned to the main battlefield where it was good at, returning to the fields of enterprise-level applications, infrastructure, middleware, microservices, command line applications, etc., and gained the favor of more and more developers in these fields. .
However, the failure of the all-out attack left many developers with the excuse that "Go's functions are weak." Some even say that [my father, Google] could not let his brother Android create a backdoor for Go.
【Related recommendations: Go video tutorial, Programming teaching】
The above is the detailed content of What are the disadvantages of go language?. For more information, please follow other related articles on the PHP Chinese website!