Two weeks using rust language experience

Download rust from the first language compiler to this day just 14 days. Briefly about the feel of the language of it.

 

First, the performance

The previously used java to write a Chinese address segmentation algorithm, with rust reimplement a bit (https://github.com/naturemickey/addressCut_use_rust). Running speed, rust than the release version of java on about twice as fast.

Java version of the code amount is more than 800 lines, while the code amount is more than 600 rust-line version.

This experience is very good, after all, has only just begun to learn rust language, write a lot of code themselves feel ugly (it is not easy to achieve, but also can not afford to think how to write good-looking), the mechanism of rust language not familiar with the library (while watching a document while writing), basically: can be used on the line, regardless of the first performance.

Over time, more familiar to rust, and then have to change the code look good, say write performance will be better.

Compile the results rust in the memory structure is compatible with the C language, which is one reason for its good performance.

 

Second, grammar

rust language there is a new thing in the syntax: RAII-- is through ownership, to borrow, to be precise mechanism lifetime memory control (does not require programmers to write code to free memory, nor GC).

I am also old programmer, and will learn some new language (I forget the language has more than many programmers have ever seen) every year, and these languages ​​have either GC, either need to manually manage memory. The compiler is able to make precise control of memory through grammar design language this is the first time to see.

But this syntax is the most frustrating place, there was a line of code to engage in a full two days to compile successfully. After graduating from college yet not a single language like rust language so let me in the course of beginner's so painful (University when first using the C language HelloWorld engage in a week), from this point of view the novice rust programmer is not friendly, but it was much better after the break through this off.

The advantage of this mechanism is obvious:

1. Performance: no GC represents no FGC, can be used for real-time system (if it is used in the case of dozens of G JVM memory, a few seconds FGC is not so simple).

2. rigor: the control of this syntax is very strict, it will force us to think in a logical process of writing code, but there is a problem causes the compiler is not passed. Write out code written in other languages ​​than the code bug less.

In addition to RAII, other things have appeared in other languages, should not a new play, such as: macro (lisp), pattern matching (Erlang, Scala), concurrency model (and go like, especially the channel, but it the Arc again, and very much like Erlang, Erlang will only copy data to another process, but rust inside more than just a reference count) .......

 

Third, ancillary facilities

1. There is a management tool module cargo, this stuff is also very convenient, a bit like in the java maven and gradle.

2.IDE: Currently no rust language IDE support, I write code using a VS Code, then hand knock command to compile. After all, version 1.0 is the language of this year (2015) in May, the future will certainly be useful tools are developed.

(. Ps the 14-day experience also has a small discovery: VSCode in two weeks even with two small version of the upgrade, Microsoft seems quite positive)

 

Fourth, in short

This is a very good language: its syntax and rigorous quality control procedures precise memory of great help - If you are familiar with it, is with respect to C ++, rust easier to write reliable software, and performance It may be better.

But for novice programmers, the rigor of rust it is a very friendly.

Reproduced in: https: //www.cnblogs.com/naturemickey/p/5014544.html

Guess you like

Origin blog.csdn.net/weixin_34162629/article/details/93461858