Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Go is compared with other languages such as python

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article introduces the knowledge of "comparing Go with other languages such as python". Many people will encounter this dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Go was designed to solve the problems encountered by Google developers at that time.

A lot of C++ code, while introducing Java and Python

Thousands of engineers

Tens of thousands of lines of code

Distributed compilation system

Millions of servers

Pain points in Google Development

Slow compilation

Runaway dependence

Each engineer only uses 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 difficulty

How to solve the 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 #, comes from Cellular languages, which further carry forward C++ 's object-oriented approach. But the designers of the Go language have a different point of view, they think it is worth learning the C language. The root cause of the persistence of C language is that it is simple enough. Therefore, the Go language is simple enough.

So they designed Go to eliminate slowness and clunkiness and improve inefficiency and scalability. Go is designed and served by people who develop large systems; it is designed to solve engineering problems, not to study language design; it is also designed to make our programming more comfortable and convenient.

However, combined with some realities within Google at that time, for example, many engineers are C-series, so the newly designed language must be easy to learn; there has been no new language in 20 years, so the newly designed language must be modern (for example, built-in GC). Based on their practical experience, they designed the language Go for their goals.

First, the characteristics of Go language

Object-oriented without inheriting polymorphism

Strongly consistent type

Interface does not need to be explicitly declared (Duck Typing)

No exception handling (Error is value)

Acronym-based accessibility

Unused import or variables cause compilation errors

Complete standard library package

Go built-in runtime (for performance monitoring, garbage collection, etc.)

II. Advantages of Go language

1. The learning curve is easy

Go language syntax is simple, including C-like syntax. Because the Go language is easy to learn, the average college student can write a high-performance application that can be used in a few weeks. In China, everyone pursues fast, which is one of the reasons why Go is popular in China.

The grammatical features of the Go language are so simple that you can hardly play any tricks, go straight, the learning curve is very low, and the start is very fast.

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

Compared with the sluggish compilation speed of Java and C++, the fast compilation time of Go is a major efficiency advantage. Go has the running efficiency close to C and the development efficiency close to PHP.

The idea of C language is to trust programmers, keep the language small, unshielded and bottom-friendly, and pay attention to the execution efficiency and performance of the language. Python's posture is to do as much as possible with as little code as possible. So I can feel how great it is that the Go language wants to unify C and Python.

3. Born from a distinguished family and pure blood.

The reason why it is said that Go comes from a famous family can be seen from the creators of the Go language. The Go language is absolutely pure. Secondly, Go language comes from Google, so there is no need to say much about Google's popularity and strength in the industry. Google has gathered a group of awesome people to launch a new programming language in a situation where various programming languages are vying for supremacy, which naturally has its strategic considerations. And from the development trend of Go language, Google still attaches great importance to its new darling, Go naturally has a good future.

Google's own son-> Golang (enough wave), comes from a noble family and has pure blood.

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

Go language can be said to be the integration of development efficiency and running efficiency, and it is a natural concurrent programming support. Go language supports all current programming paradigms, including procedural programming, object-oriented programming, interface-oriented programming and functional programming. Programmers can take what they need, combine freely, and play as much as 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 libraries at the network layer and the system layer are very useful. The lib library of Go language, Sparrow, is complete with five internal organs. There are basically most commonly used libraries in the lib library of the Go language, and although some libraries are not very good, I don't think it's a problem, because I believe these problems will be solved in the future development.

6. Easy deployment: binary files, Copy deployment

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

7. Simple concurrency

Parallel and asynchronous programming are almost painless. The Goroutine and Channel artifacts of the Go language are a great boon for concurrent and asynchronous programming. The concurrency and asynchronism of languages like C, C++, Java, Python, and JavaScript are too complex and error-prone, and Go solves this problem very elegantly and smoothly. For programmers who have been tortured by concurrency and asynchronism 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 for big data, micro services and concurrency.

Go as a language is dedicated to making things simple. Instead of introducing many new concepts, it focuses on creating a simple language that is extremely fast and easy to use. Its innovation is goroutines and channel. Goroutines is Go's lightweight thread-oriented approach, while channels are the preferred way to communicate between goroutines.

The cost of creating a Goroutines is low, requiring only a few thousand bytes of extra memory, which makes it possible to run hundreds or even thousands of goroutines at the same time. Communication between goroutines can be realized with the help of channel. Goroutines and the channel-based concurrency approach make it very easy to use all available CPU kernels and handle concurrent IO. Compared to Python/Java, running a function on a goroutine requires minimal code.

8. Stability

Go has a strong compilation check, strict coding specifications and complete software life cycle tools, has a strong stability, stability overrides everything. So why is Go more stable than other programs? This is because Go provides tools for all aspects of the software life cycle (development, testing, deployment, maintenance, etc.), such as go tool, gofmt, go test.

III. Compare other languages

Many of the language features of Go draw on its three ancestors: C _ Magi Pascal and CSP. The ideas of Go, such as syntax, data type and control flow, which inherit from the package and object-facing of CMagneGo, come from the branch of Pascal, while the language feature of Go, the concurrent model based on pipeline communication, draws lessons from the branch of CSP.

Java

Compile language, moderate speed (2.67s), the current large websites are written in java, such as Taobao, JD.com and so on. The main features are stable, good open source, with its own set of writing specifications, moderate development efficiency, the most mainstream language at present.

As a big shot in the programming language. With popularity and user base. No matter the wind and the clouds are surging, I stand still. He forced him to be strong, the breeze swept the hills; he was crossed by him, and the moon shone 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 many shortcomings of c #, JD.com, Ctrip and other large websites were developed in c #, but now they have all migrated to java.

C / C +

The ancestor of the existing programming language, other languages are born from this. The execution speed is the fastest. But it is the most complex to write and difficult to develop.

Javascript

A maverick beauty in the programming language. The front-end processing power is unmatched by other languages. The processing power of the developing js backend is also extraordinary. Eat all the food in front and back, who will you give up?

Python

Scripting language, the slowest (258s), concise code, short learning progress, fast development speed. Douban is written with python. Python's famous server framework is django,flask. But python is unstable on large projects, so some enterprises using python later migrated to java.

Scala

Compiled language, ten times faster than python, similar to java, but slow in learning, 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. Micro-service frameworks include lagom and so on.

Go

The fresh flesh of the programming world. It not only has the same concise code and development speed as Python, but also has the same execution efficiency as C language.

IV. Summary

Because the syntax of Go is similar to that of Erlang and Python, let's make a detailed comparison of these three languages.

Compared with Python's 40 features, there are only 31 Go, it can be said that Go is quite restrained in language design. For example, it has no implicit numeric conversions, no constructors and destructors, no operator overloading, no default parameters, no inheritance, no generics, no exceptions, no macros, no function decorations, and no thread local storage.

But the characteristics of Go are also very distinct, for example, it has cooperative programs, automatic garbage collection, package management system, first-class citizen functions, stack space management and so on.

As a statically typed language, Go ensures that Go is better than Python and Erlang in running efficiency, memory usage and type safety.

Go also has a wealth of data types, supporting not only complex data structures such as tables and dictionaries, but also pointers and interface types that Python and Erlang do not have. In particular, the interface type is particularly powerful, which provides a means to manage type systems. The pointer type provides the means to manage memory, which allows Go to enter the underlying software development to provide strong support.

Go has done a lot of reflection and trade-off on the feature support of objects, it has no classes, virtual functions, inheritance, generics and other features. The core of object-oriented programming in Go language is composition and method (function). The combination is very similar to the combination of the struct structure of C language, and the method is similar to the Interface of Java, but the method is more decoupled from the object and reduces the intrusion into the interior of the object. Erlang does not support object-oriented programming paradigm. In comparison, Python has the most comprehensive support for object-oriented programming paradigm.

In terms of functional programming feature support, Erlang, as a functional language, supports the most comprehensive. But basic functional language features, such as lambda, higher-order functions, curry, etc., are supported in all three languages.

In terms of control flow features, all three languages are similar. Erlang supports tail recursive optimization, which makes it convenient for functional programming. Go supports deep recursive calls by dynamically extending the protocol stack. Python is often blown up on deep recursive calls.

The concurrency models of Go and Erlang come from CSP, but Erlang is based on the concurrency implementation of actor and message passing (mailbox), and Go is based on the concurrency implementation of goroutine and channel. No matter the actor of Erlang or the goroutine of Go, they all meet the characteristics of the protocol: it is implemented and scheduled by programming language, the switch is completed in user mode, and the overhead of creation and destruction is very small. As for Python, its multi-thread switching and scheduling is based on the operating system, and because of the existence of the large pit level of GIL, it can not really achieve parallel.

And from the author's experience of concurrent programming, the functional programming syntax style of Erlang and the obscure callback (callback) usage provided by its OTP behavior framework have certain entry barriers and challenges for most programmers, such as those who come from Cmax Category + and Java. Go, known as the "C of the Internet era", has a much better programming experience with its C-like syntax and control flow, as well as the object-oriented programming paradigm.

This is the end of the content of "comparing Go with python and other languages". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report