Home >Backend Development >Golang >Which languages ​​does the go language borrow from?

Which languages ​​does the go language borrow from?

青灯夜游
青灯夜游Original
2023-01-30 18:13:523128browse

The go language draws on C, Pascal and CSP. Many of Go's language features are borrowed from its three ancestors: C, Pascal and CSP. Go's syntax, data types, control flow, etc. are inherited from C; Go's package, object-oriented and other ideas are derived from the Pascal branch; and Go's biggest language feature, the coroutine concurrency model based on pipeline communication, is borrowed from the CSP branch.

Which languages ​​does the go language borrow from?

The operating environment of this tutorial: Windows 7 system, GO version 1.18, Dell G3 computer.

1. The original intention of Go language design

1. The Go language was designed to solve the problems encountered by Google development at that time:

  • A large number C code, and at the same time introduced Java and Python
  • Thousands of engineers
  • Tens of thousands of lines of code
  • Distributed compilation system
  • Millions of servers

2. Pain points in Google development:

  • Slow compilation
  • Out-of-control dependencies
  • Each engineer only uses a part of a language
  • The program is difficult to maintain (poor readability, unclear documentation, etc.)
  • The cost of updating is getting longer and longer
  • Cross-compilation difficulties

3. How to solve the current problems and pain points?

Go hopes to become the C language of the Internet era. The fundamental programming philosophy of most system-level languages ​​(including Java and C#) comes from C, further developing the object-oriented nature of C. But the designers of the Go language have a different view. They believe that the C language is worth learning. The root of the C language's enduring popularity is that it is simple enough. Therefore, the Go language is simple enough.

So, their goal in designing Go at that time was to eliminate all kinds of slowness and cumbersomeness, and to improve various inefficiencies and scalability. Go was designed by and for those who develop large systems; it is to solve engineering problems, not to study language design; it is to make our programming more comfortable and convenient.

But combined with some of Google’s internal realities at the time, such as many engineers coming from the C department, the newly designed language must be easy to learn, preferably a language similar to C; no new language has been released in 20 years , so the newly designed language must be modern (such as built-in GC) and other situations. Finally, based on practical experience, they designed the Go language toward their goals.

4. Features of Go language:

  • Object-oriented without inheritance polymorphism
  • Strongly consistent type
  • interface does not require explicit declaration (Duck Typing)
  • No exception handling (Error is value)
  • Accessibility features based on initial letters
  • Unused import or variables cause compilation errors
  • Complete and excellent standard library package
  • Go built-in runtime (for performance monitoring, garbage collection, etc.)

## 2. Advantages of Go language

1. Easy learning curve

Go language has simple syntax, including C-like syntax. Because the Go language is easy to learn, an ordinary college student can write a usable, high-performance application in a few weeks. Everyone in China pursues speed, which is one of the reasons why Go is so popular in China.

Which languages ​​does the go language borrow from?

The grammatical features of the Go language are simply too simple. It is so simple that you can hardly do any tricks. It is straightforward, the learning curve is very low, and you can get started very quickly.

2. Efficiency: fast compilation time, high development efficiency and running efficiency

Compared with the sluggish compilation speed of Java and C during the development process, Go's fast compilation time is a major factor Efficiency advantage. Go has operating efficiency close to C and development efficiency close to PHP.

Which languages ​​does the go language borrow from?

The philosophy of C language is to trust programmers, keep the language small, not shield the bottom layer and be bottom-friendly, and pay attention to the execution efficiency and performance of the language. Python's attitude is to accomplish as much as possible with as little code as possible. So I can feel that the Go language wants to unify C and Python, which is a great thing.

3. Come from a well-known family and have pure blood.

The reason why Go comes from a well-known family can be seen from the creator of the Go language. The Go language is absolutely pure in blood. Secondly, the Go language comes from Google. It goes without saying that Google’s popularity and strength in the industry are natural. Google has gathered a group of talented people to launch a new programming language in a situation where various programming languages ​​are competing for hegemony. Naturally, it has its own strategic considerations. And judging from the development trend of the Go language, Google still attaches great importance to its new darling. Go naturally has a good development future.

Which languages ​​does the go language borrow from?

4. Free and efficient: combination of ideas, non-intrusive interfaces

The Go language can be said to be the perfect fusion of development efficiency and operational efficiency. , native support for concurrent programming.

Go language supports all current programming paradigms, including procedural programming, object-oriented programming, interface-oriented programming, and functional programming. Programmers can choose what they need, combine them freely, and play whatever they want.

5. Powerful standard library

This includes Internet applications, system programming and network programming. The standard libraries in Go are basically very stable, especially the three libraries I mentioned here, the network layer and system layer libraries are very practical. **The lib library of Go language is small but complete. **The lib library of the Go language basically contains most of the commonly used libraries. Although some libraries are not very good, I don't think it is a problem, because I believe these problems will be solved in future development.

6. Convenient deployment: binary files, Copy deployment

This is the biggest reason why many people choose Go. Because deployment is so convenient, many people now use Go to develop operation and maintenance programs. .

7. Simple concurrency

** Parallel and asynchronous programming have almost no pain points. **The two artifacts of Go language, Goroutine and Channel, are simply huge blessings for concurrent and asynchronous programming. The concurrency and asynchronous methods of languages ​​​​such as C, C, Java, Python and JavaScript are too complex to control and prone to errors, and Go solves this problem very elegantly and smoothly. For programmers who have suffered from concurrency and asynchronous programming for many years, this is a completely eye-catching feeling. Go is a very efficient language with high support for concurrency. Go is a programming language developed for big data, microservices, and concurrency.

Go as a language strives to make things simple. It doesn't introduce many new concepts, but focuses on creating a simple language that is incredibly fast and easy to use. Its only innovations are goroutines and channels. Goroutines are Go's lightweight thread-oriented approach, and channels are the preferred method of communication between goroutines.

The cost of creating Goroutines is very low, requiring only a few thousand bytes of additional memory. Because of this, it is possible to run hundreds or even thousands of goroutines simultaneously. Communication between goroutines can be achieved with the help of channels. Goroutines and the channel-based concurrency approach make it very easy to use all available CPU cores and handle concurrent IO. Compared to Python/Java, running a function on a goroutine requires minimal code.

Which languages ​​does the go language borrow from?

8. Stability

Go has powerful compilation checks, strict coding standards and complete software life cycle tools, and has strong stability , stability is paramount. So why is Go more stable than other programs? This is because Go provides tools for each aspect of the software life cycle (development, testing, deployment, maintenance, etc.), such as go tool, gofmt, go test.

3. Comparison with other languages

Many of Go’s language features are borrowed from its three ancestors: C, Pascal and CSP. Go's syntax, data types, control flow, etc. are inherited from C. Go's package and object-oriented ideas are derived from the Pascal branch. Go's biggest language feature, the coroutine concurrency model based on pipeline communication, is borrowed from the CSP branch.

Which languages ​​does the go language borrow from?

Java

Compiled language, moderate speed (2.67s), current large websites are written in Java, such as Taobao, JD.com, etc. Its main features are stability, good open source, its own set of writing specifications, moderate development efficiency, and it is currently the most mainstream language. As a big name in programming languages. Has the largest visibility and user base. No matter how strong the wind is, I remain firm and unmoving. Let him be strong, let him be strong, and the breeze will blow on the hills; let him be horizontal, and the bright moon will shine on the river.

c

#The execution speed is fast (4.28), the learning difficulty is moderate, and the development speed is moderate. However, due to the many shortcomings of C#, the predecessors of large websites such as JD.com and Ctrip were all developed in C#, but now they have been migrated to Java.

C/C

The ancestor of existing programming languages, from which other languages ​​are born. The fastest execution speed is unmatched. But it is the most complicated to write and difficult to develop.

Javascript

A unique and arrogant beauty in programming languages. The front-end processing capabilities are unmatched by other languages. The developing js back-end processing capabilities are also outstanding. Both the front and back ends are taken care of, who else would it be?

Python

Script language, the slowest (258s), simple code, short learning progress, and fast development speed. Douban is written in Python. Famous server frameworks for Python include django and flask. However, Python is not stable for large projects, so some companies that use Python later migrated to Java.

scala

Compiled language is ten times faster than python and similar to java, but the learning progress is slow, and in actual programming, if you are not proficient in the language, it is easy to cause serious performance degradation. Later, for example, Yammer migrated from scala to java. Microservice frameworks include lagom, etc.

Go

A young talent in the programming world. High concurrency capabilities are unmatched. It has the same concise code and development speed as Python, but also has the same execution efficiency as C language, with outstanding advantages.

Anyone who has been in the software industry for a while knows that there is no universal programming language, no universal development framework, and no universal solution. The emergence of any new technology should be attributed to the strong dissatisfaction of some people with old technology. Go language is no exception. For example, the dependency management of C language, C garbage collection, Java's clunky type system and heavy Java EE specifications, and the performance of scripting languages ​​​​(such as PHP, Python and Ruby) are often debated and complained about by many developer communities. The problem.

Expand knowledge:

Advantages of Go language

Go language is a master of multiple programming paradigms and embodies excellent software Engineering ideas and principles, its characteristics allow developers to quickly develop, test and deploy programs, greatly improving production efficiency. Let's take a look at the advantages of Go language compared with other mainstream languages.

1) Compared with C/C, Go language has clear dependency management and fully automatic garbage collection mechanism, so its code volume is greatly reduced and development efficiency is greatly improved.

2) Compared with Java, Go language has a concise type system, functional programming paradigm and advanced concurrent programming model. As a result, its code blocks are smaller, more concise, more reusable, and run faster in multi-core computing environments.

3) For PHP, Go language is more versatile and standardized. This makes it more suitable for building large software and better organizing the various modules together. In terms of performance, PHP cannot compete with Go.

4) For Python/Ruby, Go’s advantages lie in its concise syntax, non-intrusive and flat type system and natural multi-paradigm programming model. Like PHP, Python and Ruby are dynamically typed interpreted languages, which means they run much slower than statically typed compiled languages.

In short, the biggest advantage of Go language over most current mainstream languages ​​is its high production efficiency, advanced dependency management and type system, and native concurrent computing support. Therefore, the Go language has received attention and favor from developers in various fields since its release.

Disadvantages of the Go language

Now, let’s take an objective look at the areas where the current Go language needs to be strengthened or improved (although some Gophers don’t think so).

1) From the perspective of distributed computing, the Go language is not as mature as Erlang (some Go language code packages have appeared in this regard, and we can already see a bright future).

2) From the perspective of program running speed, although the Go language is comparable to Java, it is not yet as good as C (the gap is constantly narrowing).

3) From the perspective of third-party libraries, the number of Go language libraries is far less than that of several other mainstream languages ​​​​(such as Java, Python, Ruby, etc.). However, compared with the age of the Go language, there are already quite a few third-party libraries implemented using it, and their number continues to grow rapidly.

In addition, at a deeper level, there are also some unsatisfactory aspects in the Go language standard library, as detailed below.

1) From the perspective of language syntax, there is not much syntactic sugar in Go language syntax, which makes many Python and Ruby enthusiasts dismiss it. In addition, there are so many ways to assign values ​​to variables that it is a bit cumbersome. The most regrettable thing and what I care about most is that the Go language does not support custom generic types.

2) From the perspective of concurrent programming, the concurrency model provided by the Go language is very powerful, but there are also some writing rules that need to be understood. Otherwise, it is easy to step into the "pit". In fact, it is not recommended to call this a "pit". Because most of these so-called "pits" are dug by ourselves because we are not familiar with the principles.

3) From the perspective of garbage collection, the garbage collection of Go language uses the concurrent mark and sweep algorithm (Concurrent Mark and Sweep, CMS). Although it is a concurrent operation and takes much less time than a serial operation, it will still stop the operations of all user programs during garbage collection. This will affect applications that have relatively high real-time requirements to some extent. However, in versions after Go language 1.3, this problem has been greatly improved.

Although the Go language still has some flaws, overall, it is already a very good general-purpose programming language. Moreover, the Go language will focus on performance, reliability, portability and some feature enhancements in its future development, so the above shortcomings will gradually weaken and disappear as the version progresses.

【Related recommendations: Go video tutorial, Programming teaching

The above is the detailed content of Which languages ​​does the go language borrow from?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn