How should a Python beginner choose between Rust and Go?

Source: Internet
Author: User
Have learned a python, like his style. Like library concepts, variable definitions, programming styles are all like.
The concept of pointers is not very understanding, C + + stay in the VC6.0 era of freshman.

Want to learn another fast-compiling language. Which would compare rust and go and recommend one based on the above. (Better to compare the details of the content.)

Reply content:

If you take the time to learn, you will have the ability to compare.
/ http tour.golang.org/# 1
And
The Rust Guide

Rust does not have a runtime runtime,go, so the same work as memory management, rust tends to do at compile time, and go tends to do it at run time. This is consistent with their original purpose, rust is used to write a browser, need performance, go to write Web Services server side, runtime strong line debugging is also convenient. Although they are all general-purpose languages, there is a tendency to focus on them.
This is all my personal opinion, and other people may find this distinction meaningless. Curly braces can be independent to do a row, there is no generics, not easy to learn, not many libraries, they may think these are more important.
So compare two languages, or do your own homework. Python and the two languages are very different, without reference. Interest Related: Started using go,rust a year ago is from 0.9-dev to now 0.13-dev.

Go is not fundamentally different from C, its runtime is actually wrap a bit libc, and then provide a variety of syntactic sugar at the grammatical level. But it is much more comfortable to write than C, and the characteristics of type derivation, multiple return values, interface, GC, and so on, can make people with Python experience feel unusually gracious. However, there is no way to compare the go and Python, and after a long period of use, they will find the difference.

Rust is still in the dev phase, and it is said that the year-end beta, grammar is still changing, and all the following statements are based on 0.13-dev. Rust, if compared to go, can be compared to C + + (not rigorous).
1. Rust does not have runtime and all memory management is completed at compile time. One of the more prominent features in Rust is the "lifetime lifetime", which is the compiler used to manage an object from the construction to the destruction of the entire process, so at compile time can do memory management, to avoid developers to manually manage memory, but also to avoid memory leaks. Although this method sounds very perfect, from 0.9-dev to 0.13-dev this period, life management has become more intelligent and humanized, but really encountered the compiler can not speculate on the life of the object needs you to manually specify the time, frankly to unfamiliar people is also very nerve-racking.
2. Rust's security requirements for code are very high, and the syntax for a variety of constraints (such as a variable can not be borrow as mutable more than once, etc.), you can let the compiler at compile time to help you identify some of the points that may occur, Then compile the failure to force you to change the code to a more secure wording, the requirements of the compiler is very strict, beginners basically is every write a piece of code on his knees to ask RUSTC in the end is right, and kneeling to ask Google exactly why I wrote the wrong. During this time in rust, the rust compiler corrected many of my bad programming habits and taught the code to be fully considered (or compiled) first. This feature also allows rust to implement the words in its propaganda: prevents almost all crashes*, and eliminates data races
3. Rust writes the same program faster than go, and even tests show that it has reached Java level. (the test was seen on hacker news and put up after it was found).
4. Rust compilation is far from go so fast.
5. Go has its own goroutine, which is a lightweight thread, and rust has removed the RUSTUV from the standard library by default, using native thread for asynchrony, using it as easily as goroutine, and related discussions can be made in hacker Found on news, the Rust standard library no longer have any scheduling baked into it 。 Both have builtin channel used to achieve synchronization. (Note: Rust removed the RUSTUV from the standard library does not mean that it does not support green thread, but rather the implementation of the EventLoop to the community, the standard library interface only, Scheduler rewrite with I/O event loop Issue #4419 · Rust-lang/rust GitHub , the EventLoop in the default standard library does not support I/O).
6. It's too powerful to say that Rust has to mention its pattern matching, so please take a look at the relevant parts of Rust's documentation for interested people. It is said to originate from Haskell.

In contrast to go and rust, my choice is rust. But they are quite different from Python, and Python's experience in these two languages is not too much of a reusability.
Recently wrote a shadowsocks-rust:zonyitoo/shadowsocks-rust with rust. GitHub , you are welcome to exchange with your favorite classmates. It takes 200 hours to learn a door, and a total of 400 hours for both doors, accounting for 204,400 of your total assets (8 hours per day, 365 days per year, 70, total 0.2% hours)

So, buy and buy, both doors are good.

As if it were PG's "on Lisp", deciding whether or not to learn a language depends on the language's ability to teach you new ways of thinking. From this point of view, people with Python backgrounds, Go and Rust are good choices.



Here are some of the things that the main question says:


    • Library Concept: Rust qualified, Go qualified. Their modules are managed in a similar way to Python, and Go is more like Python,rust's management in a clear, manageable, and flexible way.
    • Variable definitions: Rust and Go are static types, and they have their own methods to avoid forcing you to play too many words with the constraints of a strong static type. Go's type system is line type, by type deduction can avoid the explicit type declaration of the local variable, unless you want to use type assert to convert the interface type to the concrete type, or the concrete type to the interface type. Rust, by contrast, has a rich type system that requires a smarter HM derivation system to determine the type of the variable, which leads to a style where you don't specify a specific type, and the compiler hints at the type of some value that it can't be sure you're going to make up the appropriate type declaration. In general, the intensity of their typing is close (unless you want to use generics to do high-level abstraction, then these more generic code will naturally be more than the equivalent version of the total no abstract code, but in this case go does not have a counterpart because go does not do generic programming).
    • Programming Style: Go and Rust like a degree of transparency, write efficient code instead of over-abstraction. So the abstraction of Rust and Go is all about starting with the concept. Go is using interface to express concepts such as IO. Writer;rust expresses concepts such as std::iter::iterator with trait. Apart from the concepts, they are written in a number of different forms of functions for manipulating data. There are no classes, only bare data, whereas in thinking these concepts are bound to functions rather than data binding. Data encapsulation takes advantage of the visibility of variables, types, and functions between libraries. Rust's trait has static distribution and dynamic distribution of two kinds of occasions, dynamic distribution based on pointer, virtual function table; Static distribution is based on generics. Go's interface is limited to dynamic distribution, which relies on pointers and reflections.

Here's an entertaining video of C + +, D, Rust, Go put together: Panel:systems programming in and Beyond, the participants are the main designers of four languages (BS, maintainers of D, Niko, Pike).


Speaking of the style of program design, I say the style of naming:


    • Go has no style guide, but it's all a CamelCase hump style to name functions and types. Mainly in accordance with the C habit of addressing some old concepts, according to these to fit into the hump style. Because there is no style guide, there are exceptions to everything, such as the go by example:structs style with all lowercase and no underlines.
    • Rust has a style guide, and the project is here and can be viewed from here. The type name uses the hump style, the function adopts the traditional C family style, snake_case. This choice coincides with the PEP8 of Python, and I believe it will make you feel good.
What is the purpose of our language learning? Solve the project problems and solve the life problems.

So we look at the problem from the two tails, the first item, go and rust are statically compiled types of language, performance I have seen before, rust is better, but the complexity of rust will be higher, from my point of view, the complexity of the increase I am not acceptable, I need a simple grammar , so that the subsequent maintenance becomes easy, and this performance gap can be ignored directly, and the release of Go is stable and orderly, go to the biggest problem is the GC and generics, the generic estimate is not solved, the GC word has been solved well, 1.5 version to solve the GC problem. Of course, two languages are also good to learn, and learn two language solutions, like @ Li Daobing said that the two will not waste your time to learn a little.

The Second Life problem, Golang and rust job openings, can go to the major recruitment site to see, Rust has recruitment? Golang do you have a job? Existing large companies are more inclined to golang or rust, this public information you can search for, it is clear that Golang major companies are in use, mainly Docker success, became the Golang language of the first killer application, Many companies use Docker as their next deployment system. At the same time, various companies have developed many successful systems using Golang. I believe that more and more companies will recruit Golang engineers, saying I have recently been recruiting, Singapore go engineer, Singapore company recruiting go engineer Welcome to people with lofty ideals to human flesh over the wall ah, I was two years from Java to go to Python two years go to go a year, the use of Java feeling is the framework of a lot of good difficult to learn, and a framework suddenly one day after I am dumbfounded (and the last version completely changed), energy consumption in the pursuit of the framework. In Ruby's heyday I also decided to try dynamic language, compared to Ruby and Python, I like the good Python syntax and its super-rich library, I found that true love, she let me and Java break up after a lot of surprises: wow, grammar super simple, I used to say 10 words with the Java, and she said a sentence to understand, communication (development) efficiency 10 times times; Wow, learning a week can be a project, you are too simple; Wow, web efficiency is much faster than Java; I thought we would be together for a lifetime, but get along with each other's shortcomings are not tolerated: operation and maintenance, All the associated libraries on Linux are downloaded again on Windows. A lot of language support multi-core concurrency, she because the JIT lock can only use multiprocessing processing, the library efficiency is low and master process Control, the main problem all collapsed. 1.5 ago I met go, her elegant temperament, she fascinated me: wow, she can develop a good program and related libraries directly across the platform; Wow, she can directly compile machine code to the production machine execution; Wow, her grammar is as simple and similar as Python, My previous code basically did not take much effort, she took over all; Wow, her pointers allow me to achieve the underlying hardware that was not previously directly accessible; Wow, it's so simple and efficient; Wow, she can keep the web and data in order without any framework middleware. Her shortcomings are young, mature available libraries are not many, but this can let me more DIY. We have been together for more than a year, and once again I feel I have found true love. Rust, too slow to develop so far minors, the pursuit of cost is too high, the risk is not controllable ah. Learn Erlang ... Escape

First you have to ask yourself, now that you have a big python, why do you want to learn other programming languages?

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

For this purpose, I recommend rust. It forces me to look at every part of the code, including, but not limited to, the scope of the variable, minimizing the API dependencies that need to be used.

These are the things I was forced to figure out when I understood borrowing,ownership. Of course, rust has a lot of other things.

All I learned was fur.

Here just to emphasize that it brings me the change of mind.


Many people say the language is very complicated.

Not really, just not used to the way rust is programmed.

Not familiar with Rust, recently learning go, personal feeling in syntax for Pythonista have natural affinity
1. No rating number
2. Core data structure approximation, slice corresponding list,map for dict, the operator style is almost the same
3.Go Although the static language, but because of the existence of automatic type deduction (: =), it doesn't bother to write.
4.duck Typing

Of course, the above is from the syntax point of view, in essence, Python and go are quite different languages, such as the attitude towards OOP, the difference between the two is very far. There are many different styles of exception handling (but this seems to be the inevitable result of go abandoning the inheritance-based type tree in the general sense). Go on the language level to bring some concurrent feature for Pythonista may be more novel, such as Channel/select and so on. In general, however, with a python background, the Go learning curve will be more stable.

Extended reading:
/ http S3.amazonaws.com/golang weekly/go_for_pythonistas.pdf The main problem is the Python beginner, who does not understand the pointer concept, wants to learn a fast-compiling language, and asks for a choice between go and rust.

I can only recommend the go language to the main topic. You want to be simple, to compile fast, and two to choose one, that can only be the go language. The rust language is relatively more complex, lower-level, and it is clearly impossible to learn rust without a deep understanding of pointer concepts.

However, I personally do not like the go language, but also once wrote a large article "Why I give up the go language." I chose the rust language, and I chose what I liked, as did the other Lord @ Zhongyuteng. Rust is so tempting for people who have been in the field for more than 10 years. (Beginners often do not experience 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.