News for hackers. Stuff that matters.
Re:A 30-minute Introduction to Rust by blub on Tuesday July 01, 2014 @11:15AM (#7971175)
Out of curiosity I implemented the two examples in C++11.

For the number add I used a unique_ptr (although returning by value would be better in every way).

For the shared state I used async with a lamba that calls transform and returns the modified vector through a future. This doesn't execute in parallel for each for loop though. I think something like Arc can be coded in C++ too - template wrapper that returns a RAII lock whick unlocks on scope end.

I think the only big difference is that some errors in Rust are happening at compile time. In the first case the original buggy code was triggering only a warning in C++.

Right now the extra compile-safety of Rust is IMO not worth giving up the other benefits of C++, especially now that C++11 with some extra static checking and good guidelines can go a long way.

Re:A 30-minute Introduction to Rust by pcwalton on Tuesday July 01, 2014 @12:00PM (#7971568)
> Right now the extra compile-safety of Rust is IMO not worth giving up the other benefits of C++

I can't speak to everyone's use case, but for ours memory safety is extremely important. C++ is not safe, and we still see tons of memory safety issues, many security-sensitive, in practice, despite using modern C++ for all new code.

Even if safety isn't as important to you, there are other reasons you might be interested in Rust: a module system, pattern matching, a standard library which offers better performance than STL for many tasks, ADTs, concepts, a package manager, etc.

Re:A 30-minute Introduction to Rust by Scramblejams on Tuesday July 01, 2014 @04:12PM (#7973214)
I get the feeling most of these commenters who think the words "modern C++" indicate some kind of near insulation from writing security bugs are, in fact, writing security bugs.

They probably think they aren't, but by definition, we are not smart enough to immediately understand the bugs we write. Otherwise we wouldn't write them.

But hey, it's not like a programmer who overestimates his own skills is a new thing.

Re:A 30-minute Introduction to Rust by Donwangugi on Tuesday July 01, 2014 @03:36PM (#7972999)
What kind of issues do you see still with modern C++11 code?
Re:A 30-minute Introduction to Rust by pcwalton on Wednesday July 02, 2014 @12:58AM (#7975284)
All kinds of memory safety issues. Heap use-after-free is very common. You can go to Bugzilla and search for sec-critical to get a list of the ones Mozilla has disclosed.
Re:A 30-minute Introduction to Rust by Dewie on Tuesday July 01, 2014 @07:26PM (#7974122)
> concepts

What are concepts in this context? It is hard to google.

Re:A 30-minute Introduction to Rust by steveklabnik on Tuesday July 01, 2014 @07:59PM (#7974271)
Re:A 30-minute Introduction to Rust by Dewie on Tuesday July 01, 2014 @08:05PM (#7974296)
Is this something that can be used in Rust? Or is it a feature that will be implemented later?
Re:A 30-minute Introduction to Rust by steveklabnik on Tuesday July 01, 2014 @08:38PM (#7974421)
I am not familiar enough with the details. We don't have an _exact_ analogue, though our Traits are similar-ish.

I've pinged #rust, I'll see if I can get someone who knows more to answer here.

Re:A 30-minute Introduction to Rust by Dewie on Wednesday July 02, 2014 @04:17PM (#7979447)
I was mostly curious if there is some kind of (formal) specifications that one can use (axioms).
Re:A 30-minute Introduction to Rust by steveklabnik on Tuesday July 01, 2014 @11:34AM (#7971359)
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.

Re:A 30-minute Introduction to Rust by blub on Tuesday July 01, 2014 @11:55AM (#7971511)
Thanks 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.
Re:A 30-minute Introduction to Rust by steveklabnik on Tuesday July 01, 2014 @11:58AM (#7971540)
Could 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.

Re:A 30-minute Introduction to Rust by sanderjd on Tuesday July 01, 2014 @12:18PM (#7971712)
As 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.

Re:A 30-minute Introduction to Rust by steveklabnik on Tuesday July 01, 2014 @12:26PM (#7971755)
> 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.

Re:A 30-minute Introduction to Rust by blub on Tuesday July 01, 2014 @01:22PM (#7972147)
I'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.

Re:A 30-minute Introduction to Rust by steveklabnik on Tuesday July 01, 2014 @01:28PM (#7972179)
Thanks, that clears it up a bunch.

All of those things are being built yet, so we don't have much to link to. There are a few work-in-progress things, for example, the postgres adapter is coming along, and rust-graphics for graphical primitives. As we get closer to release, and as they mature, we'll feature them more.

> Will the cross-platform components from Servo be included in the Rust standard library?

As we already have a package manager, I think Rust will tend to have a smaller standard library, and encourage its use more. We'll see though.

> am right now working on a UI-driven app that will be deployed to Android and on the desktop.

We support Windows, Mac, and Linux as first-class platforms, and every pull request (and additions are all through pull requests) is tested on android. iOS coming soon.

Re:A 30-minute Introduction to Rust by 59nadir on Thursday July 03, 2014 @01:23AM (#7981580)
> 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.

This doesn't seem very performance-critical. I doubt the best tool for the job is C++/Rust/C.

Re:A 30-minute Introduction to Rust by McP on Tuesday July 01, 2014 @12:46PM (#7971890)
I'm glad you mention Qt. Qt bindings are an absolute necessity before my company (which also makes cross-platform applications) could consider adopting Rust.
Re:A 30-minute Introduction to Rust by sanderjd on Tuesday July 01, 2014 @01:18PM (#7972119)
Bindings exist, but are not particularly usable at this point.
Re:A 30-minute Introduction to Rust by steveklabnik on Tuesday July 01, 2014 @12:47PM (#7971893)
There 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.
Re:A 30-minute Introduction to Rust by sanderjd on Tuesday July 01, 2014 @01:21PM (#7972133)
Yep, 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.