I have learned Python for a while and like his style. Like library concepts, variable definitions, and programming styles.
I don’t quite understand the concept of pointers, and C++ is stuck in the VC6.0 era when I was a freshman.
I want to learn another fast compiled language. Can anyone compare Rust and Go and recommend one based on the above content? (The more detailed the content, the better)
Reply content:
If you take the time to learn it yourself, you will be able to compare.
http://tour.golang.org/#1
and
The Rust Guide
Rust does not have a runtime, and go does. Therefore, the same work, such as memory management, rust tends to be done during compilation, and go tends to be done during runtime. This is consistent with their original purpose. Rust is used for writing browsers that require performance. Go is used for writing the server side of network services. The strong point of runtime is that it is also convenient for online debugging. Although they are all general-purpose languages, they have tendencies and focuses.
This is all my personal opinion, others may find this distinction meaningless. Whether the curly braces can stand on their own line, whether there are generics, whether it is easy to learn, and whether there are many libraries, they may think these are more important.
So when comparing two languages, it’s better to do your own homework. Python is very different from these two languages and has no reference.
Interests: I started using Go a year ago, and Rust has been used since 0.9-dev to 0.13-dev now.
Go is essentially not much different from C. Its Runtime actually wraps libc and then provides various syntactic sugars at the syntax level. But it is much more comfortable to write than C. Its features such as type derivation, multiple return values, interface, GC, etc. will make people with Python experience feel extremely friendly. But having said that, there is no way to compare Go and Python. After long-term use, you will find the difference between the two.
Rust is still in the dev stage. It is said that it will be in beta at the end of the year and the syntax is still changing. All the statements below are based on 0.13-dev. If Rust is compared with Go, it can be compared to the comparison between C++ and C (not rigorously).
1. Rust does not have a runtime, and all memory management is completed at compile time. One of the more prominent features in Rust is “Lifetime”, which is used by the compiler to manage the entire process of an Object from construction to destruction. Therefore, memory management can be done at compile time, avoiding developers from manually managing memory. Memory leaks are also avoided. Although this method sounds very perfect, from 0.9-dev to 0.13-dev, lifetime management has become more intelligent and humane, but if you really encounter the situation where the compiler cannot guess the lifetime of the object, you need to To be honest, it is very nerve-wracking for people who are not familiar with it when manually specifying it.
2. Rust has very high requirements for code security. It stipulates various grammatical constraints (for example, a variable cannot be borrowed as mutable more than once, etc.), which allows the compiler to help you during compilation. Find some points where bugs may occur, and then the compilation failure forces you to change the code to a safer way of writing. The requirements of the compiler are very strict. Basically, beginners will kneel down and ask rustc if it is correct every time they write a piece of code. , and kneeling down to ask Google why I wrote it wrong. During the time I was learning Rust, the Rust compiler corrected many of my bad programming habits and taught me to think about everything before writing code (otherwise it won’t compile). This feature also allows Rust to realize the sentence in its slogan: prevents almost all crashes*, and eliminates data races
3. The same program written in Rust can run faster than Go, and some tests even show that it can The speed has reached the level of Java. (I saw the test on Hacker News and posted it after I found it).
4. Rust compilation is currently far less fast than Go.
5. Go has its own goroutine, which is a lightweight thread. In the current version of Rust, rustuv has been removed from the standard library. Native thread is used by default to implement asynchronous operation. It is as convenient to use as goroutine. Related A discussion 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 threads, but it has chosen to leave the implementation of EventLoop to the community. The standard library only makes interfaces, Scheduler rewrite with I/O event loop · Issue #4419 · rust-lang/rust · GitHub, EventLoop in the default standard library does not support I/O).
6. When talking about Rust, we have to mention its Pattern matching, which is too powerful to describe. Anyone who is interested is asked to take a look at the relevant parts of Rust’s documentation. Said to be derived from Haskell.
Comparing Go and Rust, my choice is Rust. However, they are quite different from Python. The reusability of Python’s experience in these two languages is not too great.
Recently, I wrote a shadowsocks-rust in Rust: zonyitoo/shadowsocks-rust · GitHub. Friends who like it are welcome to come and communicate.
It takes 200 hours to learn one subject, and a total of 400 hours for both subjects, accounting for 0.2% of your total assets (8 hours a day, 365 days a year, 70 years, a total of 204,400 hours)
<, after comparing Ruby and Python, I fell in love with Python’s regular syntax and its super rich library. I felt that I had found true love. She gave me a lot of surprises after breaking up with Java: wow, the syntax is super simple. I used to work with If you speak Java ten times, you will understand it after just one word with her, and the communication (development) efficiency will increase ten times; wow, you can do projects after just one week of learning, you are so naive; wow, web efficiency is much faster than Java; I thought we We will be together for life, but after getting along for a long time, we increasingly feel that each other's shortcomings are intolerable: operation and maintenance deployment is very annoying, and all related libraries are re-downloaded on Linux after development on Windows. Many languages all over the world support multi-core concurrency, but they can only be processed by multiprocessing because of JIT locks. This library is inefficient and must be controlled by the main process. If the main process goes wrong, the entire library will crash. I met go a year and a half ago, and her elegant temperament immediately fascinated me: wow, she can directly transfer developed programs and related libraries across platforms; wow, she can directly compile machine code and transfer it to production. Machine execution; wow, her syntax is as simple and similar as Python, and she took over all my previous codes without much effort; wow, her pointers allow me to implement underlying hardware that I could not directly touch before; wow, concurrency So simple, so efficient; wow, she can manage the web and data in an orderly manner without any framework middleware. Her disadvantage is that she is young and does not have many mature and available libraries, but this allows me to do more DIY. We have been together for over a year now, and I feel like I have found true love again. Well, rust has grown too slowly and is still underage. The cost of pursuit is too high and the risks are uncontrollable.
Let’s learn Erlang… (escape)
First of all, you have to ask yourself, since you already know python, why do you need 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 examine every aspect of the code, including but not limited to, the scope of variables, and minimize the API dependencies that need to be used.
These are things I was forced to think clearly when understanding borrowing and ownership. Of course there are many other things in rust.
What I learned was only scratching the surface.
I just want to emphasize the changes it brought to my thinking.
Many people say that the language feels complicated.
Actually no, I’m just not used to the rust programming method
I am not familiar with Rust and am currently learning Go. I personally feel that syntax has a natural affinity for Pythonista
1. No need for semicolons
2. The core data structure is similar, slice corresponds to list, map corresponds to dict, and the operator The styles are almost the same
3. Although Go is a static language, due to the existence of automatic type deduction (:=), it is not troublesome to write
4.duck typing
Of course The above is discussed from the perspective of syntax. In essence, Python and Go are still quite different languages. For example, the attitude towards OOP is very different between the two. The styles of exception handling are also quite different (but this seems to be the inevitable result of Go abandoning the general inheritance-based type tree?). Go comes with some concurrent features at the language level that may be novel to Pythonistas, such as channel/select, etc. But in general, if you have a Python background, the learning curve of Go will be relatively smooth.
Extended reading:
http://s3.amazonaws.com/golangweekly/go_for_pythonistas.pdf
The subject’s own situation is: a Python beginner who does not understand the concept of pointers. He wants to learn a fast compiled language and is asked to choose between Go and Rust.
I can only recommend the Go language to the subject. If you want simplicity and fast compilation, and you want to choose one of the two, it can only be the Go language. The Rust language is relatively more complex and low-level. It is obviously impossible to learn Rust without a deep understanding of the concept of pointers.
However, I personally do not like the Go language, and I once wrote a large article “Why I gave up the Go language”. Like another answerer @Zhong Yuteng, I choose the Rust language, I choose what I like. For people who have been working in the C/C++ field for more than ten years, Rust is really too tempting. (Beginners often fail to understand this level.)