News for hackers. Stuff that matters.
Re:Announcing Rust 1.6 by sdegutis on Thursday January 21, 2016 @08:57PM (#10950227)
After trying to understand some Rust, it seems to me that it's just as complicated as C++, from the programmer's perspective. Was I mistaken in thinking that being simpler to program in than C++ was one of the goals?
Re:Announcing Rust 1.6 by echelon on Thursday January 21, 2016 @10:18PM (#10950532)
I don't use C++ or Rust in a daily context, but I can say without a doubt that Rust is the easier language to grasp. I don't have to decide anything about headers, linking, Makefiles, etc. to get things up and running; I can declare dependencies in Cargo.toml and it just works.

The Rust standard library feels so much more modern and easy to use than the STL. The documentation is fantastic, too.

C++ pointers, casting, OO, templates, and all the billion other language features feel like traversing down a rabbit hole. Rust is small enough to grok in a day. The syntax is incredibly expressive and a joy to use.

Re:Announcing Rust 1.6 by bjz_ on Friday January 22, 2016 @02:23AM (#10951288)
> Rust is small enough to grok in a day

I would say it is far easier to learn how to write good systems code in Rust than C++, but saying you can grok it in a day is a bit optimistic. On the surface level, perhaps. But the semantics of the type system can take longer to internalise, depending on one's background.

Re:Announcing Rust 1.6 by prewett on Friday January 22, 2016 @03:31AM (#10951501)
I've never done anything with Rust, but as a long-time C++ programmer, I expect they have done away with a whole lot of C++ complexity. For example:

Don't forget your & in your function declaration or you'll silently copy objects.

Don't forget to make your destructor virtual in your base class (don't forget to add it if the class wasn't originally going to be a base class!) or you get fun crashes on delete every once in a while.

Use "explicit" with your one-parameter constructors to avoid fun with automatic conversions.

std::string is practically useless

Use "." with classes/structs/references and "->" pointers (why am I the compiler?!)

Think you know what "a = b;" does? Think you know what the =,==,!=,<,>,^,,+,-,/,=,+=,-=,/=,^= operators do? Not unless you checked to see if someone override them!

Ever tried to read some code that uses templates?

If you declared Class(int x) and Class(char x) and then do Class('a'), it silently gets constructed with the integer version (or maybe it's with Class(const char x), can't remember, which should say something right there.)

Quick, what does "const int const x;" mean?

Quick, what does "int* a, b;" do, and is that what you expected?

Is it safe to do "a = b"? You don't know until you read through all the class hierarchies to see if the object has a pointer, and if so, if it has an assignment operator that works properly ("properly" being somewhat relative to the purpose of your object).

Fun times debugging stuff like

if (...)

   statement1;

   statement2;
Can you call a virtual function from a constructor? Which version of C++ are you using?

I have a soft spot in my heart for C++, but boy is there a lot to remember, and the mistakes/typos can kill a good half-day, minimum. I'm excited for the day I have a project I can use Rust on, looking forward to something I don't have to be always on my guard with!

Re:Announcing Rust 1.6 by masklinn on Friday January 22, 2016 @04:48AM (#10951783)
I know very little C++ and a bit of Rust so there might be mistakes:

> Don't forget your & in your function declaration or you'll silently copy objects.

I think this still exists in Rust to a limited extent but it's mitigated:

* Rust uses move semantics by default, so unless the type was specifically marked as Copy[0] it will be moved into the function which should be noticeable

* references are actual types, `&Foo` can't be confused with `Foo` and (outside of method receivers) references are created explicitly, so the callsite knows whether it's passing a reference

> Don't forget to make your destructor virtual in your base class (don't forget to add it if the class wasn't originally going to be a base class!) or you get fun crashes on delete every once in a while.

Rust has almost no inheritance support, and the realms of static and dynamic dispatches are pretty well separated (trait objects are dynamic, the rest is mostly static) so that should not be an issue.

> Use "explicit" with your one-parameter constructors to avoid fun with automatic conversions.

Rust has very little implicit behaviour (auto-deref is the main one I think), and I don't think it has implicit/automatic conversions.

> std::string is practically useless

Without more information as to its failing, I can't say whether String (and &str) is more useful. IME it certainly is useable and useful.

> Use "." with classes/structs/references and "->" pointers (why am I the compiler?!)

Yup, this is done through auto-defer (of types implementing the relevant trait of course), though it does have a separate `::` for other context.

> Think you know what "a = b;" does? Think you know what the =,==,!=,<,>,^,,+,-,/,=,+=,-=,/=,^= operators do? Not unless you checked to see if someone override them!

Can't override assignment itself, you can override other operators[1] and there is an accepted RFC for overloading augmented assignments[2]. Though these overrides are trait-based which should limit the shenanigan space somewhat.

> Ever tried to read some code that uses templates?

Rust's generics are slightly simpler, but they're lacking features (no template specialisation currently) so… not sure.

> If you declared Class(int x) and Class(char x) and then do Class('a'), it silently gets constructed with the integer version (or maybe it's with Class(const char x), can't remember, which should say something right there.)

See item above, the very declaration doesn't exist in Rust, you'd need to have two separate factory functions.

> Quick, what does "const int const x;" mean?

Should be clearer in rust, type declarations are fairly regular.

> Quick, what does "int* a, b;" do, and is that what you expected?

I think that's equivalent to `int* a; int b`?

Type information is an optional postfix addendum in Rust, so the ambiguity doesn't exist, but if you want explicit types you don't get the convenience of shortened declaration. The closest to this code would be

    let (a, b): (Box<u32>, u32)
which isn't much of a gain over

    let a: Box<u32>;
    let b: u32;
if you're not unpacking an existing structure

> Is it safe to do "a = b"? You don't know until you read through all the class hierarchies to see if the object has a pointer, and if so, if it has an assignment operator that works properly ("properly" being somewhat relative to the purpose of your object).

See above, assignment itself can't be overloaded (at least at the moment)

> Fun times debugging stuff like

I think the only places where braces are optional in Rust are non-ambiguous 1-expression lambdas (`|| {expr}` can be written as `|| expr`) and 1-expression match arms e.g.

    match foo {
        v1 => { expr1 },
        v2 => { expr2 },
    }
can be written

    match foo {
        v1 => expr1,
        v2 => expr2,
    }
> Can you call a virtual function from a constructor?

Rust doesn't have constructors so no. As for the intent, since Rust doesn't have constructors you can't have partially built values (unless you forcefully partially build them) so the answer should still be no.

[0] http://doc.rust-lang.org/std/marker/trait.Copy.html

[1] http://doc.rust-lang.org/std/ops/index.html

[2] https://github.com/rust-lang/rfcs/pull/953

Re:Announcing Rust 1.6 by dikaiosune on Friday January 22, 2016 @09:50AM (#10952977)
Wasn't the comment you were replying to lamenting these things about C++, on the implicit assumption that rust fixes them?
Re:Announcing Rust 1.6 by phyllostachys on Friday January 22, 2016 @12:37PM (#10954235)
I think the GP was but I read the parent comment as just a stab at comparing and contrasting C++ and Rust. I found it useful and interesting in that aspect.
Re:Announcing Rust 1.6 by masklinn on Saturday January 23, 2016 @04:56AM (#10957844)
Yes, I was replying for this part of the preceding comment:

> I've never done anything with Rust […] I expect they have done away with a whole lot of C++ complexity

and trying to show whether, where and how rust had done so on the various examples provided.

Re:Announcing Rust 1.6 by dikaiosune on Friday January 22, 2016 @02:21PM (#10954951)
Fair point -- that's a better reading. Too late to edit or delete :(.
Re:Announcing Rust 1.6 by dbaupp on Friday January 22, 2016 @12:17AM (#10950909)
Rust's memory management strategy has been described before as "you have to think about it, but you don't have to worry about it", which I think applies to the language more broadly in terms of a comparison vs. C++. The latter is very flexible and powerful, but generally assumes the programmer is perfect, meaning mistakes often won't be caught at compile time and are often subtle to track down, while Rust has the assumption that humans are fallible, so many mistakes are caught. The fact that they're caught means learning Rust front-loads a pile of things, because the compiler complains about them, which can easily make Rust seem more complicated despite the core concepts of ownership/borrowing really being a subset of modern C++.
Re:Announcing Rust 1.6 by Manishearth on Thursday January 21, 2016 @11:06PM (#10950689)
Multiple startups have wanted to or used Rust for systemsy components because their devs were mainly from dynamic language camps and they felt that in the process of learning Rust you end up learning systems programming, which is less so the case for C++.

Rust does have a lot of features, but for most programming often you don't have to dabble in the more advanced features, which is great. Whilst working on Servo I mostly stuck to the basic features which I was familiar with for a long time and only learned the complicated stuff after a few months out of interest.

One major difference is that Rust forces you to learn about ownership and borrowing up front. This is cognitive load you would have to take in any systemsy language at some point when learning about memory management, Rust just makes you learn it early.

Re:Announcing Rust 1.6 by dbaupp on Friday January 22, 2016 @01:17AM (#10951096)
You might be thinking of different start-ups, but I was under the impression that start-ups are using Rust not because they want to learn system programming, but because they need the low-level control but aren't confident using C++ and find Rust's compiler-driven safety very compelling.
Re:Announcing Rust 1.6 by Manishearth on Friday January 22, 2016 @04:13AM (#10951667)
Yeah, that's one part of it, but someone (I think Steve?) mentioned that some startups have realized that the process of learning Rust automatically teaches low level programming concepts, whereas with C++ it's less so. Or something like that;
Re:Announcing Rust 1.6 by steveklabnik on Friday January 22, 2016 @09:12AM (#10952773)
Yes, both Maidsafe and Terminal said things like this. They're more confident in hiring non-systems programmers because rustc is like a teacher.
Re:Announcing Rust 1.6 by steveklabnik on Thursday January 21, 2016 @09:19PM (#10950328)
We have a number of similar features, but ours are generally more straightforward since we didn't have to worry about backwards compatibility. We also have some features that C++ does not, and they have some we do not.
Re:Announcing Rust 1.6 by dikaiosune on Thursday January 21, 2016 @09:04PM (#10950263)
When I've dabbled in C++ in the past, worrying about safety (does my custom trie implementation segfault? is this iterator still valid? can I trust the code I just vendored into my repo?) was the main source of complexity, both in initial writing of my code and in debugging it. Working in Rust has been a comparative (and simple) delight for me.
Re:Announcing Rust 1.6 by vpkaihla on Friday January 22, 2016 @02:14AM (#10951261)
If you think any young language can be as complicated as C++, you're trying to be cute or do not actually know how complicated C++ actually is.