Xuan, GoLang, and Bad Code

原创
2018-08-17 16:20:47
滕菲
1052

Go

Go is the second open source programming language released by Google . It is optimized specifically for applications that run multiprocessor systems. Programs compiled in Go can be as fast as in C or C++, and are more secure and support parallel processes.


https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1534310744065&di=268b36b3b727dc557c1d0c6aa855bf22&imgtype=0&src=http%3A%2F%2Fimgsrc.baidu.com%2Fforum%2Fw%3D580%2Fsign%3D91d560b04b540923aa696376a259d1dc%2F9034f21b0ef41bd5b10a766753da81cb38db3df6.jpg


Features 

  • simple, fast, and secure

  • paralle, fun, and open source

  • memory management, secure array, and fast compile


All the features of Go will be further explained in the following part as its advantages.


Pros and Cons

Pros 1: Performance

Go is extremely fast. Its performance is similar to that of Java or C++. Generally , Go is 30 times faster than Python.


Pros 2: Efficiency

Read the following code from http://howistart.org/posts/go/1/

package main 
type openWeatherMap struct{}func (w openWeatherMap) temperature(city string) (float64, error) { 
   resp, err := http.Get("http://api.openweathermap.org/data/2.5/weather?APPID=YOUR_API_KEY&q=" + city) 
   if err != nil { 
       return 0, err 
   } 
   defer resp.Body.Close() 
   var d struct { 
       Main struct { 
           Kelvin float64 `json:"temp"` 
       } `json:"main"` 
   } 
   if err := json.NewDecoder(resp.Body).Decode(&d); err != nil { 
       return 0, err 
   } 
   log.Printf("openWeatherMap: %s: %.2f", city, d.Main.Kelvin) 
   return d.Main.Kelvin, nil}

If you are new to Go, don't be surprised. The code above shows a variety of assignments, data structures, pointers, formatting, and built-in HTTP libraries. Go makes users to stick to the basics, which makes it easy to read any code and quickly understand what's going to happen next.


Pros 3: Concurrency and passageway

Go is committed to simplifying things. Instead of introducing new concepts, it focuses on building a simple language that is exceptionally fast and simple to use. The only innovation is goroutines and passageway. Goroutines is a threaded-oriented lightweight approach to Go, ana a passageway is the preferred means of communication between goroutines.


Pros 4: Fast compling

The maximum microservices compilation using Go is only 6 seconds. Compared to the slow compilation using Java and C++, Go has a major advantage in efficiency.


Pros 5: GOFMT

Consistent code format is important. Gofmt has a powerful command lines. It is built in the Go compiler to specify the format of the code.


Cons 1: Framework

Go has no main framwork, which also caused a heated discussion in Go community. Many users think that it should not be started with using frameworks. This is true in many cases, but if you just want to build a simple CRUD API, use Django / DJRF, Rails Laravel, or Phoenix.


Cons 2: Error process

Go simply returns errors (or call stacks) through functions and expected calling code when processing errors. Although it is an effective way to do so, the scope of the error might be missed, so it is difficult to provide meaningful error information to the user. Use errors package could solve the problem.


Cons 3: Package Management

Go has no dependent libraries for a particular version, nor can it duplicate builds. By using the right tools, such as Dep and VirtualGo, Go can have a good package management.


Projects in Go

and a lot more on GitHub.


Thoughts on Go

According to Rob Pike, the reason why Go has been developed is that the difficulty of software development over the past 10 years is frustrating. Go makes coding easier and faster, and it rings alarm bells. It reminds me of the speech Niclas Hedhman gave last year at China Open Source Conference 2017.


In Evolution of Homo Nerdis: From Turing to Trash, Niclas Hedhman talked about the decline in Software Developer Quality. Because
something is hard, something new and easier has been created, which allows more people, not so intelligent people, to join the team and feel that it is still hard to do. It is the degeneration in the IT industry. If you want to know more about the speech, leave your contact and we will send it to you.


Reference

1. http://developer.51cto.com/art/201710/555200.htm

发表评论
评论通过审核后显示。