Live data from Hacker News

What is Rust and why is it so popular?

stackoverflow.blog

11–20 of 284 posts

Re: What is Rust and why is it so popular?

#11

Rust newbie here. How do you fix the compile error for the example given? I imagine it has something to do with transferring ownership, but I’m not too sure.

The example won't compile because nickname is just a reference to the first three bytes of name, but then name is cleared, so nickname would be a bad reference. That are two ways to go around this:

1. Print the nickname before clearing the name so that nickname is still valid when you print it (swap lines 4 and 5).

2. Make nickname a copy of the first three bytes of name, rather then a reference to the first three bytes of name.

    let nickname = String::from(&name[..3]);

Re: What is Rust and why is it so popular?

#14
Rust using the LLVM toolchain is a real plus, which Clang also uses in the C++ world. The Clang and Rust compilers are basically frontends to LLVM, and any language that compiles using LLVM is translated to IR (intermediate representation). All code optimization is done on the IR code itself in LLVM, which both Rust and C++ compile down to before being compiled further into assembly. That means that the same effort that goes into optimization in the C++ world for Clang is shared by the Rust community too, and any other compiler that uses LLVM.

Re: What is Rust and why is it so popular?

#15
post #4

I think one of the biggest benefits of Rust is it bakes in static analysis of code as a first class feature. Which means the language is amenable to analysis and you don't have to use third party tools to benefit from it. I also like some of the abstractions. They're clever in their simplicity. For example, an iterator over an array or vector is simply doing a for loop using pointers.

I'd like to understand what you mean by baked in. Not only does vscode need a plugin, it needs a language server running to do the static analysis. Are there analysis capabilities without the language server?

I believe he means that certain things that would need static analysis in other languages are impossible to do as part of the type system.

For example match statements need to be exhaustive. Your program won't compile unless they are.

Re: What is Rust and why is it so popular?

#16
post #12

The more pressing question: What is Rust and why is it so popular on HN?

I did an internet search for Rust jobs and it was near-zero. Would be nice but reality calls.

Weird, I did a search and I found 13,000 jobs mentioning Rust on Linkedin.

Re: What is Rust and why is it so popular?

#17
post #10

Earlier quoted context omitted.

I'd like to understand what you mean by baked in. Not only does vscode need a plugin, it needs a language server running to do the static analysis. Are there analysis capabilities without the language server?

The compiler by its self can do it, if you run it. I believe the language server is just for real time editor integration.

Gotcha, thanks. This is too tangential to belong here. I need to go better understand what exactly the language server is doing if the compiler is able to provide all the details. Going to guess it has to do with partial/progressive analysis and supplying a programmatic interface to convert errors/warnings into squiggly lines rather than text output.

Re: What is Rust and why is it so popular?

#18
Rust is a great language if you use for what was intended, system programming and as safe substitute of C and C++.

But it's not the answer of everything, to me it's nowadays abused in a lot of projects, there are instances of project where using Rust not only doesn't make a lot of sense but also can be slower than another languages, there are cases where Go is better, other where Node.js is better, other where Python is better, other where Java is better, etc. To me the Rust community seems to want to argue that everything should be rewritten in Rust, just because Rust solves every problem, while it's not.

Re: What is Rust and why is it so popular?

#19
post #12

The more pressing question: What is Rust and why is it so popular on HN?

I did an internet search for Rust jobs and it was near-zero. Would be nice but reality calls.

I just saw my first local, non-blockchain Rust opportunity, but sadly had to pass on it due to other obligations. Everyone I know writing Rust these days is introducing it to their orgs - not waiting for an open position.

Re: What is Rust and why is it so popular?

#20

The example of an error message in the blog post is the kind of thing that makes me seriously consider trying out rust. It's excellent. Are most rust error messages like that?

Yeah pretty much. A lot of effort goes into trying to make error messages as clear and useful as possible. Also `rustc --explain` can give you more general details about the class of error and there's a website that does the same. E.g. for error E0502 mentioned in the article: https://doc.rust-lang.org/error-index.html#E0502.

It's still possible to hit some edge cases where error messages aren't as helpful as they could be. But these are considered bugs and so will hopefully be fixed.

Post reply on HN