First, the original design of Go
1. The Go language was designed to solve the problems encountered by Google development at that time:
- A lot of C++ code, along with Java and Python
- Thousands of engineers
- Tens of thousands of lines of code
- A distributed compilation system
- Millions of servers
2. Pain points in Google development:
- Compile the slow
- Runaway dependence
- Each engineer uses only part of a language
- Programs are difficult to maintain (poor readability, unclear documentation, etc.)
- Updates take longer and longer
- Cross compilation difficulty
3. How to solve current problems and pain points?
-
Go hopes to become the C language of the Internet age. The fundamental programming philosophy of most system-level languages, including Java and C#, is derived from C++, which takes the object-oriented aspect of C++ further. But the designers of Go have a different view, arguing that C is worth learning. At the root of C’s enduring popularity is its simplicity. Therefore, Go is simple enough.
-
So they designed Go to eliminate slowness and clunkiness, improve inefficiencies and scalability. Go was designed by, and for, the people who develop large systems; It is to solve engineering problems, not to study language design; It’s also about making programming more comfortable and convenient.
-
However, considering some internal realities of Google at that time, for example, many engineers are C department, so the new design language must be easy to learn, preferably a language similar to C; There hasn’t been a new language in 20 years, so the newly designed language has to be modern (such as built-in GC) and so on. Finally, based on their experience in the field, they designed the language Go.
4. Features of Go language:
- Object orientation without inherited polymorphism
- Strongly consistent type
- Interface does not require explicit declaration (Duck Typing)
- No exception handling (Error is value)
- Initial-based accessibility features
- An unused import or variable causes a compilation error
- A complete and excellent standard library package
- Go built-in Runtime (performance monitoring, garbage collection, etc.)
Second, Go language advantages
1. The learning curve is easy
Go language syntax is simple, including c-like syntax. Because Go is so easy to learn, the average college student can write easy-to-use, high-performance applications in just a few weeks. In China, everyone pursues fast, which is one of the reasons why Go is popular in China.
The syntax of Go is so simple that you can hardly play tricks with it. It’s straight forward, has a low learning curve, and is very fast to learn.
2, efficiency: fast compilation time, high development efficiency and operation efficiency
Go’s fast compile time is a major efficiency advantage over the sluggish compile speeds of Java and C++ during development. Go has run efficiencies close to C and development efficiencies close to PHP.
The philosophy of C language is to trust programmers, keep the language small, do not shield the bottom layer and the bottom layer friendly, and pay attention to the execution efficiency and performance of the language. Python’s stance is to do as much as possible with as little code as possible. I could see how great it was that Go wanted to unify C and Python.
Born into a noble family, pure blood
The reason why Go comes from a famous family can be seen from the creator of Go language, which is absolutely pure. Secondly, Go language comes from Google, Google’s popularity and strength in the industry naturally need not say more. Google has assembled a group of talented people to launch a new programming language in the context of competing programming languages, which naturally has its strategic considerations. And from the Go language development trend, Google is still very important to it this new favorite, Go naturally has a good development prospects.
4, free and efficient: combination of ideas, non-invasive interface
Go is the perfect blend of development efficiency and operational efficiency, with natural concurrent programming support. The Go language supports all current programming paradigms, including procedural programming, object-oriented programming, interface oriented programming, and functional programming. Programmers can take what they want, mix it up, and play it however they want.
5. A strong standard library
This includes Internet applications, system programming and network programming. The standard library in Go is basically very stable, especially the three I mentioned here, network layer, system layer library is very useful. ** The lib library for Go has all the essentials. The lib library of **Go contains most of the commonly used libraries. Although some of them are not very good, I think they are not a problem, because I believe they will be solved in the future development.
6, convenient deployment: binary files, Copy deployment
This is the biggest reason many people choose Go because it is so easy to deploy, so many people use Go to develop operations and maintenance programs.
7. Simple concurrency
Parallel and asynchronous programming has almost no pain points. The Goroutine and Channel artifacts of Go are a great boon for concurrent and asynchronous programming. Languages like C, C++, Java, Python, and JavaScript have complex and error-prone concurrent and asynchronous controls, and Go solves this problem gracefully and smoothly. For programmers who have suffered from years of concurrency and asynchrony, this is a complete eye-opener. Go is a very efficient language with high support for concurrency. Go is a programming language for big data, microservices, and concurrency.
-
Go as a language strives to keep things simple. Instead of introducing many new concepts, it focused on building a simple language that was surprisingly fast and simple to use. The only innovations are goroutines and channels. Goroutines are a lightweight thread-oriented approach to Go, and channels are the preferred means of communication between Goroutines.
-
Goroutines can be created cheaply, with only a few thousand bytes of extra memory, which makes it possible to run hundreds or even thousands of Goroutines simultaneously. Communication between Goroutines can be achieved through channels. Goroutines and the channel-based concurrency approach make it very easy to use all available CPU cores and handle concurrent IO. Running a function on a Goroutine requires minimal code compared to Python/Java.
8. Stability
Go has strong compilation checks, strict coding specifications, and complete software lifecycle tools, which are very stable. Stability trumps everything else. So why is Go more stable than other programs? This is because Go provides tools for all parts of the software life cycle (development, testing, deployment, maintenance, and so on), such as Go Tool, Gofmt, and Go Test.
3. Compare other languages
Go borrowed many of its language features from its three ancestors: C, Pascal, and CSP. The syntax, data types and control flow of Go are inherited from C, and the ideas of package and object facing of Go are derived from Pascal branch. The biggest language feature of Go, the coroutine concurrency model based on pipeline communication, is borrowed from CSP branch.
Java
Compile language, moderate speed (2.67s), the current large websites are written with Java, such as Taobao, JINGdong and so on. The main features are stable, open source, with its own set of writing specifications, moderate development efficiency, the most mainstream language at present.
As a major player in programming languages. It has the largest popularity and user base. No matter the storm, I stand firm. He did what he did, the wind blew over the hills; The moon shines across the river.
c
Fast execution speed (4.28), moderate learning difficulty, moderate development speed. However, due to c# has many shortcomings, jingdong, ctrip and other large websites were developed in c#, but are now migrated to Java.
C/C++
The granddaddy of existing programming languages, from which all other languages have sprung. The fastest execution time is second to none. But it’s the most complicated to write and the most difficult to develop.
Javascript
A proud and beautiful maverick in a programming language. The front-end processing power is unmatched by any other language. The developing JS backend processing capabilities are also outstanding. Front and back. Who else?
Python
Script language, the slowest (258s), simple code, short learning progress, fast development speed. Douban is written in Python. Python’s famous server frameworks are Django, Flask. But Python was less stable on large projects, so some businesses that used Python later migrated to Java.
scala
Compiled languages, ten times faster than Python and about the same as Java, but slow to learn, and in real programming, if you don’t have a good command of the language, you can easily suffer a serious performance degradation. Later, for example, Yammer migrated from Scala to Java. Microservice frameworks include Lagom, etc.
Go
The young meat of the programming world. High concurrency is unmatched. It has the advantages of simple code and development speed like Python and execution efficiency like C language.
Four, the last
Because Go’s syntax is similar to Erlang and Python, let’s make a detailed comparison between the three languages.
With only 31 features compared to Python’s 40, Go can be said to be fairly restrained in language design. For example, there are no implicit numeric conversions, no constructors and destructors, no operator overloading, no default arguments, no inheritance, no generics, no exceptions, no macros, no function modifications, and no thread-local storage.
But Go also has distinctive features, such as coroutines, automatic garbage collection, package management system, first-class citizen functions, stack space management, etc.
Go, as a statically typed language, ensures that Go is better than Python and Erlang in terms of running efficiency, memory consumption and type safety.
Go is also much richer in data types, supporting Pointers and interface types in addition to complex data structures like tables and dictionaries, which Python and Erlang don’t have. Interface types in particular are particularly powerful, providing a means of managing the type system. Pointer types provide a means of managing memory, which makes Go a powerful enabler for low-level software development.
Go does a lot of reflection and trade-offs in support of object-facing features. It has no classes, virtual functions, inheritance, generics and other features. The core of object-oriented programming in Go is composition and function. Combination is similar to the combination of STRUCt structure of C language, and the method is similar to Java Interface, but the use method is more decoupled from the object, reducing the intrusion inside the object. Erlang does not support the object-oriented programming paradigm. Python has the most comprehensive support for the object-oriented paradigm.
As a functional language, Erlang has the most comprehensive support for functional programming features. But basic functional language features, such as lambda, higher-order functions, curry, and so on, are supported in all three languages.
Control flow feature support is similar in all three languages. Erlang supports tail-recursive optimization, which makes functional programming easier. Go supports deep recursive calls by dynamically extending the coroutine stack. Python is often overrun with deep recursive calls.
The concurrent models of Go and Erlang both come from CSP, but Erlang is a concurrent implementation based on Actors and messaging (Mailbox), and Go is a concurrent implementation based on Goroutine and channel. Both Erlang actor and Go Goroutine are full of the characteristics of football procedures: implemented and scheduled by programming language, switching is completed in user mode, the creation and destruction cost is very small. As for Python, its multithreaded switching and scheduling is implemented based on the operating system and cannot be truly parallel due to the cratering of the GIL.