In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains "what are the advantages and disadvantages of Go language". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn what are the advantages and disadvantages of Go language.
Advantages of Go
Reason 1: performanc
Go is extremely fast. Its performance is similar to that of Java or C++. In our use, Go is generally 30 times faster than Python. The following is a baseline comparison between Go and Java:
Reason 2: language performance is important
For many applications, the programming language simply acts as the glue between it and the dataset. The performance of the language itself is often irrelevant.
But Stream is an API provider that serves the Fortune 500 and more than 200 million end users. Over the years we have optimized Cassandra, PostgreSQL, Redis, and so on, but have finally reached the limits of the language we use.
Python is great, but it doesn't perform well in serialization / deserialization, sorting, and aggregation. We often encounter the problem that when Cassandra uses 1ms to retrieve data, Python needs 10ms to convert it into an object.
Reason 3: developer efficiency & Don't be too innovative
Packagemain
TypeopenWeatherMapstruct {} func (wopenWeatherMap) temperature (citystring) (float64,error) {
Resp,err:=http.Get ("http://api.openweathermap.org/data/2.5/weather?APPID=YOUR_API_KEY&q="+city)"
Iferrroomroomnil {
Return0,err
}
Deferresp.Body.Close ()
Vardstruct {
Mainstruct {
Kelvinfloat64`json: "temp" `
} `json: "main" `
}
Iferr:=json.NewDecoder (resp.Body). Decode (& d)
Return0,err
}
Log.Printf ("openWeatherMap:%s:%.2f", city,d.Main.Kelvin)
Returnd.Main.Kelvin,nil}
If you are a novice, you won't be surprised to see this code. It shows a variety of assignments, data structures, pointers, formatting, and built-in HTTP libraries.
When I am programming, I like to use the advanced features of Python very much. Python allows you to use the code you are writing creatively, for example, you can:
Use MetaClasses to self-register categories during code initialization
Replacement of true and false
Add functions to the list of built-in functions
Reload the operator in a wonderful way
There is no doubt that this code is interesting, but it also makes it difficult to understand when reading other people's work.
Go forces you to keep laying the groundwork, which makes it easy to read arbitrary code and quickly figure out what's going on.
Note: of course, how easy it is depends on your use case. If you want to create a basic CRUD API, I suggest you use Django + DRF, or Rails.
Reason 4: concurrency & channel
Go as a language is dedicated to making things simple. Instead of introducing many new concepts, it focuses on creating a simple language that is extremely fast and easy to use. Its only innovation is goroutines and channel. Goroutines is Go's lightweight thread-oriented approach, while channels are the preferred way to communicate between goroutines.
The cost of creating a Goroutines is low, requiring only a few thousand bytes of extra memory, which makes it possible to run hundreds or even thousands of goroutines at the same time. You can use the channel to achieve communication between goroutines. The Go runtime can represent all the complexity. Goroutines and the channel-based concurrency approach make it very easy to use all available CPU kernels and handle concurrent IO-- without complex development. Compared to Python/Java, running a function on a goroutine requires minimal boilerplate code. You just need to use the keyword "go" to add a function call:
Go's concurrency approach is very easy to use and interesting compared to Node; in Node, developers must pay close attention to the processing of asynchronous code.
Another excellent feature of concurrency is the race detector, which makes it easy to figure out whether a race condition exists in asynchronous code.
Reason 5: fast compile time
Currently, the compilation time of the * * microservice written in Go takes only 6 seconds. Compared with the sluggish compilation speed of Java and C++, the fast compile time of Go is a major efficiency advantage. I love fencing, but it's even better when I still remember what the code is supposed to do.
Packagemain
Import (
"fmt"
"time") funcsay (sstring) {
Fori:=0;i
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.