Half a month experience using the rust language

Source: Internet
Author: User

From the first download of the Rust language compiler to today just 14th day. Simply say something about the language.

First, performance

The former Java-written in a Chinese address segmentation algorithm, with Rust re-implemented (Https://github.com/naturemickey/addressCut_use_rust). The release version of Rust is about a few times faster than Java.

The Java version of the code is more than 800 lines, while the rust version of the code is more than 600 lines.

This experience is still very good, after all, just started to learn rust language, a lot of code themselves feel very ugly (can realize it is not easy, still have no ability to think how to write well), the rust language mechanism and library are unfamiliar (while reading the document side write), basically is: can use on the line, Regardless of performance first.

After a while, more familiar with rust, and then change the code to look good, say not write performance will be a little better.

Rust's compilation results are compatible with the C language in the memory structure, which is one of the reasons for its good performance.

Second, the grammar

The rust language has a new syntax: raii--is the use of ownership, borrowing, life-time mechanisms to achieve accurate memory control (no programmer to write code to free memory, no GC).

I am also an old programmer, learning new languages every year (I forget more languages than many programmers have seen), and these languages either have GC or need to manage memory manually. It's the first time I've ever seen a language that allows the compiler to precisely control memory by using a grammar design.

But this grammar is also the most frustrating place, there was a line of code to make a full compilation of two genius success. After graduating from college, there was no language like the rust language that made me so miserable in my beginner's process (the first HelloWorld in the C language in college for one weeks), from which Rust was unfriendly to novice programmers, but it was much better after that.

The benefits of this mechanism are also obvious:

1. Performance: No GC means no FGC, can be used to do real-time system (if the JVM uses dozens of g of memory, a FGC is not a few seconds so simple).

2. Rigor: This grammatical control is very rigorous, it will force us to write code in the process of logic thinking, one but the problem will lead to the compilation does not pass. The code written in this way will have fewer bugs than the code written in other languages.

In addition to RAII, everything else appears in other languages, not new, such as: Macro (Lisp), pattern matching (Erlang, Scala), concurrency model (like go, especially channel, but its arc is very similar to Erlang, It's just that Erlang is sure to replicate the data to other processes, and rust just has one more reference count inside ....

Third, supporting facilities

1. There is a module management tool cargo, this thing is also very convenient, a bit like the Java maven and Gradle.

2.IDE: Currently the rust language does not have IDE support, I write code with VS code and then hand-tap command to compile. After all, the 1.0 version of the language is this year (2015) May, there will certainly be a good development tool to appear.

(Ps. In this 14-day experience There is also a small discovery: Vscode in this two weeks unexpectedly has two minor version of the upgrade, it seems that Microsoft is very positive)

Four, in short

It's a pretty good language: its rigorous syntax and precise memory control are a great help to the quality of the program--if you're familiar with it, rust is easier to write reliable software than C + + and can perform better.

For novice programmers, though, Rust's rigor is less than friendly.

Half a month experience using the rust language

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.