2 ms·
Box<T> is roughly equivalent to unique_ptr, and you're correct, returning by value would be better. Rust idiom is to use stack allocation and borrowing wherever
by steveklabnik 12y ago
Box<T> is roughly equivalent to unique_ptr, and you're correct, returning by value would be better. Rust idiom is to use stack allocation and borrowing wherever possible.
> I think the only big difference is that some errors in Rust are happening at compile time.
This is true in these examples, except maybe the enforcement of not using a pointer after you've sent it to a task.
That said, there are other examples, like iterator invalidation, where Rust is completely memory safe, unlike C++. Furthermore, Rust has significantly less undefined behavior and odd edge cases. These are in C++ for good reason, but they're still there.
> with some extra static checking and good guidelines can go a long way.
They can go a long way, and that may be enough for you. Big applications continue to have security issues due to problems that Rust would prevent, though: in the last Pwn2Own, all of Firefox's bugs would not have been possible in Rust, for example.
- blub 12y agoThanks for the details. In all honesty I am probably not a target for Rust anyway, I almost never use C++ for systems programming, but rather for (cross-platform) application development. It would seem that neither Rust nor Go serve this area and probably do not intend to do it either.
- steveklabnik 12y agoCould you expand on why? I ask because the largest test case for Rust, Servo, is a cross-platform application, and I'm always looking to improve our marketing.
- sanderjd 12y agoAs someone who has researched using Rust for a cross-platform GUI application and looked at Servo for ideas of how to do so, I think the libraries for the GUI layer are still very immature. Servo is mostly a rendering engine that draws its final product directly to a canvas, which is great for the content area of a browser window, but different than what most GUI applications need. (Definitely interested in being corrected by the far more knowledgeable Servo developers here.) Having said that, immature libraries are to be expected at this point, and I do think Rust is very well positioned to have really good ones for this use case in the short to medium term.
- steveklabnik 12y ago> the libraries for the GUI layer are still very immature. This is absolutely true, but that's a different concern than "It would seem that neither Rust nor Go serve this area and probably do not intend to do it either," which is what I'm curious about. One of the open questions with GUI toolkit stuff is that Rust does not have named parameters, but Qt, for example, uses them heavily.
- McP 12y agoI'm glad you mention Qt. Qt bindings are an absolute necessity before my company (which also makes cross-platform applications) could consider adopting Rust.
- steveklabnik 12y agoThere are several people working on it. I'm not sure what the current state is, but I know that mapping was one of the big issues.
- sanderjd 12y agoBindings exist, but are not particularly usable at this point.
- sanderjd 12y agoYep, I think we are in complete agreement. My inference from looking at the language and community is that Rust absolutely intends to serve this use case.
- blub 12y agoI've only based my impression on a cursory look on the Rust API docs, so I might be wrong, but I did not find any references to database libraries, UI toolkits, multimedia and so on. I did not know about Servo, so I will have to look into it. Will the cross-platform components from Servo be included in the Rust standard library? To give you some background about the kind of apps I was referring to - I am right now working on a UI-driven app that will be deployed to Android and on the desktop. I am using C++, Qt and platform code where necessary.