preface

I wrote a content about Hyperf framework of PHP before, and said that the coroutine efficiency and performance of Go language are very high, pushing Go language to the forefront. Recently, I have been watching various video tutorials, brochures and articles, taking this opportunity to summarize my learning achievements. I am a PHP programmer, and I often see that I need to be familiar with THE Go language on recruitment profiles. Many people on major programming exchange websites start to sing bad about PHP. Go does make up for many shortcomings of PHP, so what are the characteristics of Go in my eyes as a PHPer?

1. High efficiency

Go is so efficient that it supports concurrency natively, not patched like other languages. Go came outin 2007, when there were already multi-core processors. That’s why Go was built with concurrency in mind, using the Goroutine keyword to implement coroutines. Coroutines can be understood as a lightweight threads, thread is for type, coroutines is coordinated, is the system thread scheduling, ctrip is language level users to schedule, want to understand the things or need the calculation of solid foundation, learn more closely behind about (reflect) to learn the importance of calculation basis. Swoole is a network communication engine written by C++ that provides PHP with high performance programming support. It allows PHP to achieve asynchronous performance with fully synchronous code. Although it is very easy to use, it always gives people a sense of not pure.

Statically typed, strongly typed, compiled languages

The language is a static type, type definitions, compiled languages, static type refers to compile time checking type, so the efficiency will be higher than the dynamic type language, the isolation of the code is good also, using a third-party development kit is not prone to conflict, strong type definition refers to the use of a variable must be clear before the variable type, There are a lot of implicit conversions for basic operations like PHP and Python that are convenient but not rigorous. Sometimes there will be some hard to find bugs, there is a point is a strongly typed language learning to improve code readability, improve the rigor of the code, conducive to the maintenance of the project, said is compiled in the source code to a one-time converted into binary instruction operation above the operating system, that is why particularly efficient, compiled languages are usually not cross-platform, Different systems need to be recompiled, or compilation parameters need to be set according to the target platform, which I encountered when learning to use Docker to compile Go gin framework.

3. Simple features

Python and PHP have a lot of built-in methods and syntactic sugar to implement many basic functions. It is not easy in Go. It feels a little primitive. It’s also easy to pick up. Go does not have the concept of a class class, but uses structures, methods and other functions similar to class, which will be discussed in detail later. Go language also retains the pointer feature. In my practice, I found that it can reduce the memory consumption of some copies when passing some values to improve efficiency.

4.Go Language ecology

I also want to talk about Go related software Docker and Kubernetes, both of which are developed with Go language. In my eyes, Docker has overturned the traditional software architecture just like Go. Long ago, all services were on one machine, and the whole business would be affected if a service was suspended. Even fatal errors have to roll back the entire server mirror, database data are lost, then slowly on the database cloud, object storage, until now Docker appears, Kubernetes microservices appear, very flexible, to avoid a single point of failure, flexible and free, Kubernetes encounter burst traffic can automatically scale, There is no need to restart the server to improve the configuration of the server. In fact, many languages can be developed for these two software, but with the development of technology at any time, Docker and Kubernetes are more and more popular. Companies at home and abroad are using Go language. Ali Cloud and Tencent Cloud SDK have seen Go, and there must be a lot of problems and demands that we need to solve with Go language in the future.

conclusion

Go solves the problems of low efficiency in the development of C and C++, and low efficiency in the operation of Python and PHP. Although Go is not a perfect language, it is very practical and can solve many pain points. Each language has its own characteristics. The above are my own humble opinion, if there is any mistake or wrong place, welcome to point out!