How should a beginner of Python choose between Rust and Go?

Source: Internet
Author: User
I have learned a piece of Python and like his style. Like library concepts, variable definitions, and programming styles. I don't quite understand the pointer concept. C ++ stays in the VC6.0 era of freshman year. I want to learn another quick compilation language. Which one can compare Rust and Go? We recommend one based on the above content. (More details) I have learned a piece of Python and like his style. Like library concepts, variable definitions, and programming styles.
I don't quite understand the pointer concept. C ++ stays in the VC6.0 era of freshman year.

I want to learn another quick compilation language. Which one can compare Rust and Go? We recommend one based on the above content. (More details) reply content: you have the ability to compare it after learning it yourself.
Http://tour.golang.org/#1
And
The Rust Guide

Rust does not have runtime, And go has runtime, so the same job, such as memory management, tends to be done during compilation, and go tends to do it at runtime. This is consistent with their original goal. rust is used to write the browser and requires performance. go is used to write the server of the network service. It is also convenient to debug the runtime on line. Although they are all general-purpose languages, they tend to be focused.
This is my personal opinion. Others may think this difference is meaningless. Whether curly braces can be used as a single line independently, whether they are generic, hard to learn, and there are not many libraries. They may think these are important.
Therefore, if you want to compare two languages, do your homework. Python differs greatly from the two languages without reference. Interests: Go was used a year ago, and Rust was used from 0.9-dev to 0.13-dev.

In essence, Go is not much different from C. Its Runtime is actually wrap libc, And then it provides various syntactic sugar at the syntax level. However, it is much more comfortable to write than C. The features of Type derivation, multiple return values, interfaces, GC, and so on will make people with Python experience feel exceptionally friendly. However, Go and Python cannot be compared. After a long term of use, they will be more different.

Rust is still in the dev stage. It is said that at the end of beta, the syntax is still changing. All the following statements are based on 0.13-dev. If Rust is compared with Go, it can be compared to C ++ and C (not rigorous ).
1. Rust has no Runtime, and all memory management is completed during the compilation period. One of the most prominent features in Rust is the "life-time survival", which is used by the compiler to manage the entire process from the construction of an Object to the destructor. Therefore, memory management can be implemented during the compilation phase, this avoids manual memory management by developers and Memory leakage. Although this method sounds perfect, from 0.9-dev to 0.13-dev, lifetime management has become more intelligent and user-friendly, however, when the compiler cannot predict the lifetime of an object, you must manually specify it. To be honest, it is also a headache for unfamiliar people.
2. rust has very high requirements on code security. It provides various syntax constraints (for example, a variable cannot be borrow as mutable more than once ), the compiler can help you find Bugs during compilation, and the compilation failure forces you to change the code to a safer way. The requirements of the compiler are very strict, for beginners, they simply kneel down and ask rustc if it is right or not, and kneel down and ask Google why I wrote it wrong. During the time it was learning Rust, the Rust compiler corrected many of my bad programming habits and taught me to fully consider writing code (otherwise it would not compile ). This feature also enables Rust to implement the sentence in its publicity: prevents almost all crashes *, and eliminates data races
3. Rust writes the same program and runs faster than Go. Some tests even show that it has reached the Java level. (The test result is displayed on Hacker News and can be found ).
4. Rust compilation is far less fast than Go.
5. go has its own goroutine and is a lightweight thread. Rust has removed rustuv from the standard library in the current version. By default, Native thread is used for Asynchronization, which is as convenient as goroutine, relevant discussions can be found on Hacker News, The Rust standard library no longer has any scheduling baked into it . Both have builtin channels for synchronization. (Note: Rust's removal of rustuv from the standard library does not mean that it does not support green thread. Instead, it chooses to pass the EventLoop implementation to the community. The standard library only serves as an interface, scheduler rewrite with I/O event loop · Issue #4419 · rust-lang/rust · GitHub By default, EventLoop in the standard library does not support I/O ).
6. When it comes to Rust, you have to mention its Pattern matching, which is too powerful to express. If you are interested, please take a look at the relevant part of Rust's document. It is said that the source is Haskell.

In contrast to Go and Rust, I chose Rust. But they are quite different from Python, And the reusability of Python's experience in these two languages is not too great.
Recently I used Rust to write a shadowsocks-rust: zonyitoo/shadowsocks-rust · GitHub You are welcome to join us. It takes 200 hours to learn a course, and 400 hours to learn two courses, accounting for 365 of your total assets (8 hours a day, 204400 days a year, 70 years, 0.2% hours in total ).

Therefore, you can buy and buy both of them.

It seems that PG's "On Lisp" Statement determines whether you want to learn a language depends On whether the language can teach you new ways of thinking. From this perspective, Go and Rust are good choices for people with Python backgrounds.



Let's talk about the things mentioned by the subject:


  • Library concept: Rust qualified, Go qualified. Their module management methods are similar to those of Python, while Go is more like Python and Rust management methods are clear and easy to manage while being more flexible.
  • Variable definition: Rust and Go are both static types. They have their own methods to prevent you from being forced to limit the strong static type and Typing too many words. The type System of Go is line type. You can avoid explicit type declaration of local variables by type derivation, unless you want to convert the interface type to a specific type using type assert, or convert the specific type to the interface type. In contrast, Rust has a rich type system, which requires a smarter HM derivation system to determine the type of the variable, which leads to a style that you do not specify a specific type first, when the compiler prompts the type of some values, it cannot be determined and you can add the corresponding type declaration. In general, their typing intensity is close (unless you want to use generics for high-level abstraction, then, these more widely used codes will naturally have a larger amount of unabstracted code than the corresponding version, but in this case, Go is not applicable to the application because Go cannot do generic programming ).
  • Programming style: Go and Rust like a certain degree of transparency. They need to write efficient code instead of over-abstraction. Therefore, Rust and Go are both beginning with concepts. Go uses interfaces to express concepts, such as io. Writer; Rust uses trait to express concepts, such as std: iter: Iterator. Apart from concepts, they all write functions in different forms for manipulating data. No class, only bare data. In terms of thinking, these concepts are bound with functions rather than data. Data encapsulation uses the visibility of variables, types, and functions between libraries. Rust's trait has two types of scenarios: static distribution and dynamic distribution. Dynamic distribution is based on pointer and virtual function tables, and static distribution is based on generics. The Go interface is limited to dynamic distribution. It depends on pointers and reflection.

Here is an entertaining video about C ++, D, Rust, and Go: Panel: Systems Programming in 2014 and Beyond.The panelists are the main designers of the four languages (BS, D maintainers, Niko, Pike ).


The style of programming is mentioned above. Let me talk about the naming style:


  • Go does not have a style guide, but it uses a CamelCase hump style to name functions and types. According to the habits of C, the old concepts are adapted to the camper style. Because there is no style guide, there are exceptions in everything, such as Go by Example: StructsThe style is case-insensitive.
  • Rust has a style guide. The project is here., From hereBrowse. The type name adopts the camper style, and the function adopts the traditional C family style, namely, "Snail ke_case. This option is exactly the same as PEP8 in Python, and I believe it will make you feel happy.
What is the purpose of language learning? Solve project problems and solve life problems.

So let's look at this problem from the two sides. The problems in the first project, Go and rust are both static compilation languages. In terms of performance, I have seen a comparison, and rust is better, but the complexity is also higher than that of rust. From my perspective, I cannot accept the increase in complexity. I need a simple syntax to make subsequent maintenance easier, however, this performance gap can be ignored directly, and the release of the Go version is stable and orderly. The biggest problem of Go is GC and generics, which won't be solved by generic estimation, GC is a good solution for the moment. Version 1.5 solves the GC problem. Of course, it is also good to learn both languages. The solution to learning both languages is like the one mentioned by @ Li daobing.

In my second life, golang and rust are looking for jobs. You can go to the major recruitment websites to see if rust is hiring? Have golang been hired? Currently, large companies prefer golang or rust. You can search for this public information. Obviously, golang is used by all major companies, mainly docker's success, as the first killer application in the golang language, many companies use docker as their next deployment system. At the same time, various companies have also developed many successful systems using golang. I believe that more and more companies are hiring golang engineers. I have recently been hiring Go engineers in Singapore and Go engineers in Singapore. Welcome to anyone with lofty ideals. I switched from Java two years to python two years to go one year. I have used Java and feel that the framework is so difficult to learn, I was dumpfounded one day after the upgrade of a framework (just like the previous version), and I spent all my energy chasing the framework. I also decided to give a try on the dynamic language when Ruby was very popular. After comparing Ruby and Python, I liked Python's regular syntax and its rich library, I think I found my true love. She had a lot of surprises after breaking up with Java: Wow, the syntax is very simple. I used to say ten sentences to Java and I knew it when I spoke to her, the efficiency of communication (Development) has been improved by ten times. Wow, you can build projects within one week. You are too simple. Wow, the web efficiency is much faster than that of Java; I thought we would stay with each other for a lifetime, but after getting along for a long time, I feel that the disadvantages of the other party are intolerable: O & M and deployment are annoying, and all associated libraries on Linux are re-downloaded after development on Windows. When many languages around the world support multi-core concurrency, she can only use multiprocessing to process the JIT lock. This database is very inefficient and has to be controlled by the main process, and the master and slave databases crash across the board. A year and a half ago, I met go. Her elegant temperament fascinated me: Wow, she can directly transfer the developed programs and associated libraries across platforms. Wow, she can directly compile the machine code and upload it to the production machine for execution. Wow, her syntax is as simple and similar as Python. She took over the previous code without much effort. Wow, her pointer allows me to implement the underlying hardware that I previously could not directly access. Wow, concurrency is simple and efficient. Wow, she can well manage the web and data without any framework middleware. Her disadvantage is that she is younger and has few mature and available databases, but it can make me more DIY. We have been with us for more than a year, and I once again feel that I have found my true love. Rust, the development is too slow, so it is still minor, the pursuit cost is too high, and the risk is uncontrollable. Learn Erlang... (Escape)

First, you have to ask yourself why you have to learn other programming languages since you already have python?

As for me, the answer is to expand my programming thinking.

For this purpose, I recommend rust. It forces me to examine every part of the Code, including but not limited to, the scope of the variables, and minimize the api dependencies that need to be used.

These are what I was forced to think clearly when I understood borrowing and ownership. Of course, rust has many other things.

All I learned is what I learned.

I just want to emphasize the changes it brings to my thinking.


Many people say that this language is complicated.

Actually, no. It's just not used to rust programming.

I am not familiar with Rust and I am studying Go recently. I personally feel that syntax has a natural affinity for Pythonista.
1. No score is required.
2. The core data structure is similar. The slice corresponds to the list. For dict, the map operator style is almost the same.
3. Although Go is a static language, it is easy to write because of the existence of automatic type derivation (: = ).
4. duck typing

Of course, the above is discussed from the syntax perspective. In essence, Python and Go are quite different languages. For example, the attitudes towards OOP are far different. The exception handling style is also quite different (but it seems that Go has abandoned the inevitable result of the inheritance-based type tree in the general sense ?). At the language level, Go comes with some concurrent feature which may be novel to Pythonista, such as channel/select. But in general, with the Python background, the Go learning curve will be relatively stable.

Additional reading:
Http://s3.amazonaws.com/golangweekly/go_for_pythonistas.pdf The subject's situation is: a beginner in Python, who does not understand the pointer concept, wants to learn another fast-compiled language and needs to select one between Go and Rust.

I can only recommend the Go language for the subject. You must be simple, compile quickly, and select either of them as the Go language. The Rust language is relatively more complex. It is obviously impossible to learn Rust without a deep understanding of the pointer concept.

However, I personally do not like the Go language. I also wrote a major article titled why I gave up the Go language. Like another Q & A @ Zhong Yuteng, I chose the Rust language and I like it. Rust is tempting for people who have been exploring the C/C ++ field for more than a decade. (Beginners often cannot understand this layer .)

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.