Home > Article > Backend Development > Why are more and more major Internet companies starting to use Go language?
More and more major Internet companies are beginning to use Go language
, such as Tencent, Meituan, Didi, Baidu, Google, and bilibili. ..
And ByteDance, which initially used Python
, has even fully embraced Go
. So many leading companies at home and abroad are starting to use it. What are its advantages? Now let’s talk about some of its advantages.
ps: Of course, there are also members of Go-To-Byte
who want to learn the Go language and use it to complete the big project of the youth training camp~
Speaking of advantages, in some aspects it is mostly because it has some features that others do not have, or it optimizes the troublesome areas of others. In comparison, it is Even better. Then let’s take a look at some of the features of Go
, but before understanding the blunt features, let’s take a look at several other common languages:
This is not a comparison, not to say who is good or bad, but a pony crossing the river, it varies from person to person~
C language
was invented by great gods Ken Thompson and Dennis Ritchie in 1971, and the leading developers of Go language
One of them is Ken Thompson, so it is similar to C language in many places, (such as struct, Printf, & value operator)
C/C
Also used as many languages for beginners, they are all directly compiled into machine code, so the execution efficiency will be higher, and they all do not require an execution environment, which reduces the user's usage cost It will be lower, unlike many languages which also require the installation of the required environment.
Because of these reasons, their one encoding or compilation is only applicable to one platform. For different operating systems, sometimes it is necessary to modify the encoding and then compile, and sometimes it is enough to recompile directly. .
And it is also "very unfriendly" to developers? You need to deal with the problem of garbage collection (GC)
yourself. When coding, you also need to consider, when will the memory on the heap be free and delete
? Will the code cause memory leaks and be unsafe?
As a rookie who learned Go
from Java
, I haven’t officially developed it yet. I feel that development efficiency will be lower than Java
(personal feeling, don’t complain if you don’t like it)
~?
Java
It is directly compiled into bytecode (.class)
. This compilation product is an intermediate code between the original encoding and machine code. In this case, the Java
program requires a specific execution environment (JVM)
, the execution efficiency will be lower, and there may be virtualization losses. But this also has the advantage that it can be compiled once and executed (cross-platform)
in multiple places. And it also comes with GC
.
Python,
JS is an interpreted language, they
are not It needs to be compiled and can be run after interpretation. So Js also
requires a specific execution environment (browser engine) .
virtualization loss. JsOnly requires a browser to run, so it is also
cross-platform.
C/C The performance is very high because
it is directly compiled into binary without virtualization loss, Go thinks it is pretty good;
Java The
automatic garbage collection mechanism is very good, Go I think it is also good; the
Js one-time encoding can be applied to multiple platforms
,Go feels great; and Go
naturally has high concurrency capabilities, which is unmatched by all languages. So let’s briefly summarize it!
GC
problems
program is amazing. In fact, most languages have the concept of Runtime
, such as Java
, the running environment of its program is JVM
, needs to be installed separately. For Java
programs, without special processing, they can only run on machines with JMV
environments. <p>The <code>Go
program comes with its own running environment. The Runtime
of the Go
program will be packaged into a binary product as part of the program and run together with the user program. , that is to say, Runtime
is also a series of .go code and assembly code, etc.
. Users can "directly" call Runtime
's functions (such as make( []int, 2, 6), this syntax is actually to call the makeslice function in Runtime)
. For the Go
program, simply put, it can run without installing additional operating environment. Unless you need to develop Go
programs.
Because of this, the Go
program does not need to deal with the GC
problem, and it is entirely left to Runtime
to handle (it needs to be packaged anyway Together)
.
Different from C/C
, for multiple platforms, modification may be required code and then compile. It is also different from Java
's one-time encoding, which is compiled into intermediate code and run on virtual machines on multiple platforms. Go
Only needs to be coded once, and it can be easily compiled into machine code and run on multiple platforms.
It is worth mentioning that its cross-platform capability is also given by Runtime
, because Runtime
has the ability to shield system calls to a certain extent.
C
The ability to handle concurrency is also Not weak, but due to the high coding requirements of C
, if you are not a very experienced and professional C programmer
, many failures may occur. And Go
may not have so much experience, but it can still write high-concurrency programs with good performance.
It is worth mentioning that its super high concurrency is also the ability given by Runtime
to handle coroutine scheduling.
For developers, install the Golang
environment After that, you can use the official standard library to develop many functions. For example, there are many commonly used packages shown in the figure below:
Go itself has a
rich tool chain, (For example: code formatting, unit testing, benchmark testing, package management...)
The above is the detailed content of Why are more and more major Internet companies starting to use Go language?. For more information, please follow other related articles on the PHP Chinese website!