The C language of the Cloud era: Go language expert Quiz picks

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

The Go language, known as the C language of the cloud era, makes a great tradeoff between software development efficiency and operational efficiency. This allows it to adapt to the rapid development of Internet applications, but also in high-concurrency, high-performance development scenarios in a duck to the top. That's why many internet companies, especially startups in the cloud computing world, choose the Go language as an important part of their technology stack. Therefore, it is necessary to focus on and learn the Go language for the vast majority of developers.

In the 149th issue of expert question and answer, we asked about Go and invited @hyper0x (it) as a master guest.

This article has compiled some excellent questions and answers in this expert question and answer.

Issues related to Go language usage scenarios

Main usage Scenarios for Go:

  • There are a number of major scenarios, such as network programming, including Web systems, API applications, download applications, game backend, and various server programming, such as processing logs, data packaging, virtual machine processing, file systems, and so on. There are a lot of related projects on GitHub, but you can also refer to: Https://github.com/GoHackers/awesome-go-China
  • Besides these, go is also suitable for the development of distributed system, Gateway class system (micro-service Gateway), Database agent, basic service and so on, as long as the service-side program with high concurrency and high available demand can be developed with Go.
  • In-memory database, Google developed the groupcache,couchbase part of the build.
  • Cloud platform, at present, many foreign cloud platform using Go development, Cloudfoundy part of the formation.
  • There is also an gobot framework for IoT, and there are official solutions for mobile development (though further development is needed).

What are some of the more promising open source or commercial projects for Go in big data applications and in big data applications (mass storage, batch processing, streaming, data forecasting, etc.)?

  • Go is well suited for data mining (especially crawlers), data analysis, and data storage. There are many libraries on GitHub, especially in terms of mining and storage. (There are many domestic, such as: Pholcus (Reptile), TIDB (storage), etc.).
  • There are a lot of mass storage, such as Infuxdb, Cockroachdb, Tidb. Other aspects of GitHub also have a lot of open source projects, not listed. However, commercial projects are rarely present.
  • In the big Data World, Go and Python are also very good combinations.

Go as a system programming language is intended to replace C + +, what system programming use scenarios?

  • Who can not replace who, who will not be easily replaced, can only say in the new era more suitable for the basic work, "The cloud era of C language" means in the cloud computing era is more suitable for basic work, the reality also confirms this. We can use go to easily write system-level basic commands, you can also use go to write software to replace C + + software, such as Caddy can replace Nginx, and so on.

At present, many e-commerce platform is developed in PHP, Go is suitable for the development of e-commerce platform language?

  • We use Go to write API gateways, basic services and infrastructure components, as well as some application-level systems that require higher performance, all of which are global base systems. The advantages are obvious, and are sufficient for both development efficiency and operational efficiency.
  • E-commerce PHP is mainly due to the development of fast, but from the perspective of saving operation and maintenance costs and improve operational efficiency, Go is also a good choice. PHP makes page rendering easier, and Go is better at doing concurrent task processing. In our division is so divided. PHP may be more efficient in developing some tasks, but the program is less efficient than Go.

AI, such as the famous project, is not the go do, how to use go to do artificial intelligence?

  • The go language is inevitable because Google pushes it into the AI world. At present, go to do AI-related work is mainly to take tensorflow car, because the deep learning framework TensorFlow already have Go API. Believe that go will gradually become the main role.

Is it appropriate for startups to choose the Go language as their technology stack?

  • A lot of companies are doing this now, but a technology company generally does not use only one language as the base technology stack. I recommend the startup team to use the Go language as its basic technology stack (one).

The advantages of the Go language

What are the benefits of Go:

  • Simple to deploy: Go compilation generates a static executable file with no external dependencies other than glibc. This makes deployment incredibly easy
  • Concurrency is good: The language level supports concurrency, which is the biggest feature of Go. Goroutine and channel make it easy to write high-concurrency server-side software, and in many cases there is no need to consider locking mechanisms and the various problems that arise.
  • Good language design: from the engineering point of view, Go's specifications are simple and flexible, with a complete tool chain, such as gofmt can be automatically typeset code
  • Good execution performance: suitable for writing bottleneck business, very memory saving
  • A rich library of standards: built-in libraries and a powerful network library

The go language compared to Java, PHP, the most widely used language in the execution speed and concurrent programming advantage is obvious, in addition to these two points, Go has other advantages?

  • The tradeoff between engineering capability, development and operational efficiency is the two outstanding features of Go. These two aspects at first see nothing, but scrutiny up really is for the implementation of software engineering, can play a very big role. When a team to do a big lump of projects or a large project, the advantage is still very obvious.

Rust no Gc,nim has GC but compiled to C performance better, ask Golang in and Rust, Nim competition will gradually in the weak?

  • Look at a language to see its "Godfather", ecological construction and development history. Nim's grammar I also like, but no big company support, development is not guaranteed.
  • Rust is also a very good language, basically pure community support, but the learning threshold is very high, ecology is not too mountains, need to wait and see.
  • For me, Go is ideal for technical teams. Of course, if you just play with the Nim is still very good, if you want to exercise mind Rust is also a very good choice.

The Python language is more advantageous in cloud computing, data mining, and machine learning than the Go language and Python. There are a lot of machine learning libraries that have Python versions and no Go versions. I have always heard that the performance of the Go language is more powerful than python, and I don't know which aspect is stronger than Python.

  • The Go language is already in the field of data mining and is beginning to dabble in data analysis and machine learning.
  • Performance is positive, only consider the difference between the explanatory language and the compiled language can determine the performance difference, not to mention the performance of the Go language in the compiler language is also the leader. You can write your own Web Server test in a different language.

What are the benefits of Go compared to back-end development languages such as Python, Perl, and Ruby?

  • The advantages of Go are obvious compared to scripting languages-good performance. Of course, the disadvantage is that there are too few grammatical sugars, but this is also a reflection of the engineering philosophy of Go.
  • The concurrent programming model of GO is very unique, and it eliminates the developer's own handling of complex concurrent processing scenarios. This is well worth learning from the developers.

Does the Go language support multithreading?

  • The go language constructs a user-level threading mechanism and model on the kernel thread, and it can be said that the concurrency model of Go is built on the kernel thread. Go perfectly wraps the traditional multithreaded programming model and effectively shields the complexity of multithreaded programming.

Issues related to the development of Go language ecology

What changes can go 2.x make? Do you think Go will support the high-level syntax such as generics?

  • Now it's too early to talk about Go 2.x, you can search for issue with go2 tag on GitHub's Go official project. But even then it is not possible to fully speculate on the exact set of features of Go 2.x.
  • Go release 2.x will support the paradigm, personally, I want to add the most features are generics, but not without generics.

Will Google deploy a central repository like Pip and npm to drive Go? It feels like the management of Go is too loose at the moment.

  • Go is currently developing a third-party dependency on Administrative tools DEP, but has not heard of being prepared to develop a maven-like tool, but the latter can easily be used by DEP (or glide) + home-made transit +gitlab to meet most needs.

The ecology of Java is very prosperous, how is Go in the ecological construction development?

  • The ecological benefits of Go are still in cloud computing, microservices and data mining, and are extending to emerging areas such as machine learning. As far as I know, some startups in the field of machine learning and robotics are already using it.
  • As a country with a large number of users, Go has a very good momentum in our domestic development. Whether it's a big company or a start-up company, the proportion of Go is increasing.

Will Golang replace Java's position? What are the future trends of Go?

  • The underlying technology stack is hard to replace. We should take an open mind and use multiple technology stacks in parallel.
  • With Google-LED technology trends, Go should have a very good development prospects.

Related issues during Go use:

Before we learned that the GC mechanism of Go is defective, which causes the service process to block and the concurrency mechanism to fail briefly, is this problem solved in 1.8?

  • As early as Go 1.4,go officially has started to improve the GC, after so many versions of the effort, so far the GC has not been a problem, the specific introduction please see: http://www.infoq.com/cn/articles/2016-review-go

Golang runtime includes runtime, but also has garbage collection, compared with the traditional Java performance advantages? What problems have you encountered while using the Golang language?

  • For comparison, you can refer to this article: Https://making.pusher.com/golangs-real-time-gc-in-theory-and-practice
  • The Go language was previously criticized by the GC caused by the scheduling of the pause time is too long, but now is not a problem at all.

How can Golang interact with other languages and learn from each other?

  • There are official CGO at the language level.
  • However, it is recommended to use a common protocol-based approach to interaction, such as thrift, GRPC, and so on, the heterogeneous system is the way.

The go language uses the method of message passing to implement concurrency, but also supports synchronous lock concurrency, and the advantages and disadvantages of channel mode and synchronous lock mode. The Go language channel is currently in a single application, can follow-up support for distributed channel development?

  • Channel is more in line with the Go style, the transferred value will be copied, so generally safe, the application of the lock is typically encapsulated concurrency security objects or protect global variables. The biggest advantage of the channel is that concurrent programming is easy and clear, and the disadvantage is that it is slightly heavier than the lock.
  • Distributed channels can actually be implemented in many third-party frameworks or software, such as GPRC, Thrift, or various MQ.

What are the pits or points of attention in GO development? For example, because it is different from programming or design ideas in other conventional languages, it can lead to incorrect use.

  • Briefly, there are a number of things to note in terms of using slice types, channel types, GO statements, defer statements, function arguments, variable assignments, and interface utilization. For example, the underlying array of a slice value is what it looks like, knowing that it is better to use slice.
  • Another example is how to manipulate channel values to avoid blocking or panic.

Go some of the modules are slow, such as Go Log,json part is somewhat slow, ask the production environment can only use some third party to replace? How do you pits about the pits that have been trampled here?

  • Log is also IO, so it must be slow, which requires a tradeoff between performance and log completeness. In many cases, the contents of the log need to be carefully weighed. Slow generally there are two reasons, one is the calculation of the amount (direct reason), one is the additional memory allocation (indirect reason), need to be optimized from these two aspects.
  • Plus, we're simply encapsulating a layer of Logrus and Uber's zap, with a uniform interface that's good scalability and better performance. JSON this piece actually we still use the official plan, but some simple JSON directly stitching the string, the performance will be better.

Concurrency and parallelism are some differences, I would like to write a real parallel program what is the proposal, now just configure the next gomaxprocs.

  • Go 1.5 does not have to set this environment variable, the default value is the same as the number of logical CPUs of the current machine, can make full use of multi-core computing.
  • In the Go language to write a program as long as the focus on how to do it, parallel things to runtime. But as with many technologies, it is necessary to know the underlying principle to build the superstructure better.

The bottom of Go is how to implement "Duck mode", what is the principle? Do you have any impact on performance?

  • You can look at the https://golang.org/doc/faq#guarantee_satisfies_interface here, the specific way you can read the Go compiler source code.
  • Of course there will be performance impact, but write the program and do the software must consider the maintenance period (90% of the life cycle), to have a good design. This is important. In addition, assigning a value of a non-interface type (and non-pointer type) to a variable of an interface type results in a new memory allocation. This should be noted.

Is there any good maturity plan for Go package management?

  • Go is officially working on a solution called DEP, but it's still a while before it's officially released. Before this, I personally first Glide, the other GB in some cases is also applicable.

What are some of the more powerful Go development tools?

  • Personally think the graphical development tools, VS Code, Gogland, liteide are more useful
  • Intellj idea + Go plugin is also a good choice

The book has the use of Go Tool Trace, to recommend Golang a variety of tool tutorial instructions, PPROF, CPU, memory, race conditions and so on.

  • There is no way to use the Go Tool Trace in the book, I have another free Go command tutorial, the address is: https://github.com/gohackers/go_command_tutorial. This tutorial has an introduction to most of the go commands, but with limited energy, there is no way to use the Go Tool Trace. I also hope to have gopher help me to perfect this tutorial. Of course, once I have time, I will make up.

In the Windows environment, want to output GC information, CMD: Set godebug=gctrace=1 Mygoapp.exe, so there is no information output.

  • Please refer to https://golang.org/pkg/runtime/#hdr-environment_variables. Also, you need to verify that the environment variable is set correctly.

Other related issues

Currently do Java development, but very much like go, ready to go to go, for the domestic go market what do you think? What's there to pay attention to?

  • The market is certainly not as good as Java and PHP, but is rushing forward fast. If you really like the go language, it is recommended to find a full-time go development work. Of course, it is more prudent to use go to write something and accomplish some tasks directly in the current position. The most important thing is to apply this technology to practice and to generate value.
  • The main need to pay attention to the design and writing procedures, Java is too oo, so Java programmers are easy to fall into OO thinking, in fact, in addition to OO there are other excellent programming ideas. BTW, I was from Java turned around.
  • As for the transformation of programming ideas, you can also refer to the content of a Go Daniel blog Http://tonybai.com/2017/04/20/go-coding-in-go-way.

With five or six years of C #, and then to node. JS Development, it's been three years now, what are the advantages of using GO development compared to node. js? Is it necessary to learn the Go language?

  • If you hate node. JS's callback hell, you can resolutely turn Go,go's concurrent programming model to greatly reduce the developer's mental burden, allowing you to easily develop concurrent programs.
  • In addition, Go's programming philosophy and Unix philosophy are very similar, engineering concept is also very worthy of absorption.
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.