Live data from Hacker News

What is Rust and why is it so popular?

stackoverflow.blog

111–120 of 284 posts

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

#111
post #38
post #34

Over the last couple of months I've been slowly, but steadily playing with Rust. I work on embedded systems and while it's gaining traction only slowly, it feels to me reasonably likely that we'll be seeing non-trivial applications in the next 8-10 years. I doubt that we'll see it used for low-power/resource-constrained firmware, but lots and lots of embedded systems are now bulky Linux boxes with years of uptime, an…

I think that Rust's approach to safety -- soundly eliminate UB in safe code -- comes at the high cost of complexity. This affects how easy it is to write custom compilers (very important in the embedded space), but it is also not necessarily the best way to reduce bugs. For some, this cost is acceptable, and I'm sure some people may even welcome the high-level-looking code [1] that Rust and C++ support, but I think t…

You've been asserting this for a while now, without really describing what you mean by "Zig's approach." What features are you thinking of here, and why would we expect them do any better than existing tools in C++ (or even C)? For example, "modern C++" is also often described as having similar benefits to safety.

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

#113
post #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 t…

This is a broad over-simplification of compiler engineering. LLVM IR is a very leaky abstraction, and there are plenty of optimization passes which make sense for one but not the other. Plenty of optimization passes can and do assume that the LLVM IR is "roughly clang-shaped".

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

#115
post #80
post #74

Earlier quoted context omitted.

As someone who never much got into systems programming, Rust feels like a breath of fresh air. It makes systems programming way more accessible for me personally, coming from non-systems languages. Learning to write C well is just not something that appeals to me at all. From mostly an outsiders' perspective, I just don't think C is a very nice programming language. It looks easy to to pick up and it probably is (for…

> As someone who never much got into systems programming, Rust is a breath of fresh air. I think that's part of the problem :) Because Rust looks high level it appeals to people used to high-level programming. But once you get into systems programming, the issues are different from high-level programming, and you're less happy to pay for features that solve other problems. What I'm saying is, obviously, a matter of t…

The nice part about Rust is that if you don't want to use a given feature, you can just ignore it. You can totally write Rust in a struct + functions style, just like C.

If you want higher level abstraction only in some parts of your codebase, you can do that too. It's easy to mix-and-match.

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

#116
post #26

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?

In my experience, the vast majority are exactly like the error they show. Some are even better. I haven't hit a warning in ages that hasn't been able to be auto fixed by `cargo fix`. However not all of them are. Back in the pre-async/await days you'd end up with some really gnarly implicit types in some really big functions with lots of returns. Then sometimes you'd make a mistake on one of the returns and the compil…

Thanks for the kind words. I would say that subpar errors fall in one of two camps: incredibly uncommon (so we haven't "exercised" that muscle to clean them up) or incredibly hard to deal with. I monitor the issue tracker so if you do encounter a confusing error, file a ticket, we treat them seriously.

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

#117
post #80
post #74

Earlier quoted context omitted.

As someone who never much got into systems programming, Rust feels like a breath of fresh air. It makes systems programming way more accessible for me personally, coming from non-systems languages. Learning to write C well is just not something that appeals to me at all. From mostly an outsiders' perspective, I just don't think C is a very nice programming language. It looks easy to to pick up and it probably is (for…

> As someone who never much got into systems programming, Rust is a breath of fresh air. I think that's part of the problem :) Because Rust looks high level it appeals to people used to high-level programming. But once you get into systems programming, the issues are different from high-level programming, and you're less happy to pay for features that solve other problems. What I'm saying is, obviously, a matter of t…

You're probably correct, but I think Rust is probably fitting a solid place of making developers used to higher level languages actually -look- at embedded programming. It's an entry point.

Now, for those who get involved enough in it, they might find issues with the language, and that will provide them incentive to get comfortable with C. Or maybe they won't; maybe they'll get turned off at that point, or maybe they'll find making Rust work a better option, or they'll find still another language that is even closer to C, without the holes.

But either way, providing a way to move in that direction without having to immediately accept all the baggage C brings seems like a good thing. It certainly has moved my mindset from "screw embedded unless it's beefy enough I can run Erlang" to "well, maybe; Rust looks interesting". And I figure if I get comfortable enough with looking into the space, I either

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

#118
post #73

Earlier quoted context omitted.

Can Rust do things like heap compaction? You could do it by hand I guess but its not exactly trivial. There's probably a whole class of problems the GC still excels at. JVM tooling is also pretty nice. Can you trivially get deep app metrics from any Rust program?

I think you're asking rhetorically, but just in case: 1. Rust-the-language doesn't know anything about allocations, so strictly speaking, it cannot. Furthermore, without a GC, it's unclear how it could in the first place, given that a compaction would invalidate all pointers to that memory. 2. Certainly not to the same degree as the JVM, given that there's nothing inherently to inspect, like there is in languages wit…

> Rust-the-language doesn't know anything about allocations

AIUI, Rust knows more about allocations than it should, since it's still limited to a single global allocator, and Box (which relies on that global allocator) is implemented via compiler magic and cannot be supplemented by equivalent library code. If Rust supported "pluggable" allocators in some fashion, fancy features (including heap compaction, although I find that a bit dubious TBH) might become easier to implement.

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

#119
post #39
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.

Yes and no. It provides some kinds of (important!) static analysis out of the box, but at the cost of complexity, which directly adversely affects some other kinds of (also important) static analysis. For example, there are sound static analysis tools that guarantee no undefined behavior of C code, but AFAIK, such tools can at best only work on a subset of C++, because of its complexity. Rust goes all out on eliminat…

> sound static analysis tools that guarantee no undefined behavior of C code, but AFAIK, such tools can at best only work on a subset of C++, because of its complexity.

What tools are these, and why haven't they been deployed across every C codebase to prevent memory safety bugs?

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

#120

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.

Are you familiar with C++? That example is roughly equivalent to: #include #include #include int main() { std::string name { "Vivian" }; auto nickname = std::string_view { name }.substr(0, 3); name.clear(); std::cout which will happily compile, but whose behavior is undefined.

Is the behavior undefined because std::string makes a deep copy of the string? I thought 'Vivian' would be placed in read-only memory and as long as you don't modify it, you can hold read-only references to it.
Post reply on HN