This is a creation in Article, where the information may have evolved or changed.
I've spent a lot of time playing with some new languages – especially to point out that rust has captured my imagination. We used a lot of Ruby, Erlang, and JavaScript (later angular) code in chef. Here are some of the things I like about these languages:
- ruby feels like it's always beating in my head." Whipuptitude "section. It's easy, you can simply sit down and start coding, you don't have to run into difficulties. It also has the same expressive power that I like in Perl. The more you become proficient in this language, the more you will feel as if you can express yourself in English (native language).
- erlang and OTP excellent operation. Those pattern matching, actor concurrency, single assignment, and delightful runtime results in running, managing, debugging product Services is a pleasure, I think it's ugly, but when you master it, you'll find some kind of simplicity.
- Modern JavaScript has become more and more pleasing in its own way. For example, you can easily get community contributions of various packages and frameworks, such as Angular's pure expressiveness, and the language of the regular use of the part of progressive weight loss to make the experience enjoyable. I didn't like it in the past.
So – I decided to write some rust and go, because in my world everyone seemed to be fascinated by it.
Rust
I started noticing rust a few months ago. This language has been designed to replace C + + and is suitable for low-level development, with high security guarantees and innovative memory management (borrowing borrowing). And it has my favorite language features like Erlang: pattern matching, actor style concurrency, default immutable variables.
I don't have a lot of history with C + +. Honestly speaking, my strong-type language programming experience is not much. As a system administrator, we usually make patches for someone's program (I do a lot of this, but patching is not like developing from scratch). In my limited experience, I found that the compile-and-run debugging loop is annoying. I confess that this is my personal ignorance: if I take the time to understand the language, I can certainly find the pitfalls that hit me regularly.
So I started using rust to rewrite a ruby-developed command-line tool. I don't mean to sell or share, it's just an excuse for me to learn a language (motivation). Here's what I observed:
Cargo Package Manager Very good
Cargo is a very good front-end tool for Rust project management. Creating a new rust project, adding tests, dependencies, and so on are all very easy and concise.
Expressive as a scripting language
Rust is like a very expressive underlying scripting language. See the following link for more information:
Https://gist.github.com/adamhjk/e296257b32818ee8691d.js
Some things like As_slice () and VEC may take a little time to explain, but it's very straightforward. The following links allow you to review these functions:
Https://gist.github.com/adamhjk/ead9de51d6f6d3aefeb2#file-review-rs
Again, I don't think writing Rus is more difficult than writing a scripting language. It takes a little time to get used to the fact that, for example, I return an option from Have_dot_git (CWD) and extract the value (or throw an error) with a pattern match-but when you realize what's going on underneath the engine, you'll think it's great.
Strongly typed strong type
In all the strongly typed languages, I always felt that I was wrestling with the compiler. I find it hard to trust the compiler, so it can stop me from doing something stupid, rather than saying it doesn't understand my way. (I admit that this is an emotional flaw of my own) rust for the following three reasons people feel different:
- It's compiled error messages are very clear, directly pointing out where is wrong, It also often provides you with a precise solution ("You don't want to ...").
- The compilation loop is very fast, and when my code compiles successfully, it always runs exactly as I think. The concepts of
- borrowing, using the term and so on, take time to get used to. However, the compiler does represent your interests every time, again, the error message and the rules are clear. Rust does not have a traditional garbage collector-but it has very clear rules to indicate how long things should live on stacks and heaps. These rules and areas are tightly bound and, to a certain extent, feel natural.
The most important thing for me is that my code has never segfaulted or panicked. These are the experiences I've never had before in the underlying system programming language. If the compiler accepts my input, it starts running-fast and accurate.
Rust Some libraries don't exist yet
Rust is still evolving, almost 1.0 (translator: Now 1.2 is out). As a side effect, many high-level libraries do not yet exist or have not been written. A good (small) example is that the command line syntax Parsing Library does not yet exist. One package is included in the standard library, but the interface is not working well. There are some hopeful libraries in GitHub, but the best one (from interfaces, functionality, etc.) has no way of compiling with the latest rust. (This is due to the fail! (..) Macro is changed to panic! (..) -It's not a big deal, but it's also a fact that rust is still evolving. )
Similarly, cargo can get a good dependency-but it doesn't say that those packages are available, like NPM, RubyGems, or CPAN.
The final idea about rust
Rust is a powerful, highly thought-out system programming language with some very good and useful features. (Generics, traits, pattern matching, actor concurrency, borrowing-abound). It takes a tax burden to learn and use the "rust method" to solve the problem-the language itself is simple, but it needs to contend with a few different concepts. (Translator: If you understand functional programming Scala, Haskell, you will feel that learning rust soon)
That is, for the first time I feel I can believe that I can quickly write a fast, efficient system code for the bottom line. The compiler is very friendly and it provides very useful and clear error hints. -rust will be a force to be reckoned with when it evolves to 1.0 and the ecosystem of the library starts to heat up.
Go
Many people say a lot about how the go is magical. When I spent a few hours refactoring something with go, I understood the appeal.
Go smaller
If you have some programming experience with C-derived languages, then you can quickly learn some surface areas of the language. There are a lot of things you already know how to use in the language: If/then/else,switch,for. They use the syntax you already know. It provides shorthand syntax to simplify some types of lengthy typing work. (for example: =).
Go is self-righteous-it's a lot of things
When you read "How to write Go code," It starts telling you how to write everything from the top-level source directory to what you're going to do with go. Go's toolchain knows how to get the structure and do the right thing-compile binary into your ' bin ' directory, run your tests, capture dependencies.
Static output is good-and reality, anything you compile locally will be consumed by your users and feel good.
Go to avoid your method
The rust compiler lets you be sure how your idea will work in the underlying code, and go sits in the middle. Language is strongly typed, but in practice it seems to be possible to infer your intentions most of the time. Example:
Https://gist.github.com/adamhjk/5a475b8dd45971a4e814#file-dot_git_dir-go
The only type annotation in a function is input and output-everything else is work. Feel fast, easy, approachable and very little trouble.
Run-time failure of Go
The rust runtime is very, very difficult to make mistakes. The compiler convinced me that I checked every code path and always made sure I covered every corner. Go is happy to do what I tell it-although the compiler will block my stupidity, but it will not prevent me from doing something like this:
Https://gist.github.com/adamhjk/9c7eae1d053a1788f581#file-panic-go
The Nineth line blindly assumes that the positive expression finds a match and then causes a run-time error message. This will never happen in rust.
Https://gist.github.com/adamhjk/2eb74d326242a9093f9e#file-current_branch-rs
Because the return type that the Regex captures is the option, the compiler knows that I need to handle all possible values. I really can't choose to ignore it. This happened when I wrote the code-in go, I wrote only what I thought I wanted, and then I knew what was wrong when I was running (this is a very small fix). In rust, the compiler told me the first time I tried this function, I haven't processed the none result on the option return value.
speed, accessibility, and library
The tradeoff is interesting. Go code uses less time to write, language is easy to access, and the ecosystem is powerful. It makes me feel like I'm working in a scripting language, but at the same time avoiding most notorious mistakes. Because the only language structure is the most common structure, in the language feel very simple, there is no time.
Go has a huge library ecosystem, a clear way to find them, and a simple way to get them.
So... Rust or go?
The pragmatic answer, I think, is ' do what is good, which is practical. ' Go can replace what people write in Ruby, Pythong, or Perl. It is a simple, approachable language, plus a strong type and incredibly eco-system. I understand why people like it. Static binary, very good ecosystem, with very good. I wrote the go code about a few times faster than rust.
But, I like rust better. I like it. Pattern matching, generics, default immutable data. I like it if my code compiles, the likelihood that the program will run as I designed it is extremely high. I would like to live in that world when I imagined that an ecosystem would be built on such a basis. It's better than a world where I rely on a lot of language use cases and I don't really feel comfortable in space. I'm pretty sure rust will be very attractive to you if you use C + +. And if you use Ruby or Python, go is more appealing to you. However, I think once the rusts ecosystem takes off, it will also attract those who use Ruby/python.
I think of a lesson from a high-level recruitment rule, one of the rules is that he/she has to be surprised in some ways by someone who is "good" in many ways, usually not great. Go is giving me this feeling-it's good in every way, but not grabbing my heart, doesn't make me feel very excited about not having these things in my existing ecosystem, and rust is absolutely amazing to ensure that the code you write is right and safe at runtime-it's a revelation.
You must try both at the same time.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.