Live data from Hacker News

Some notes on Rust

lambda-the-ultimate.org

81–90 of 113 posts

Re: Some notes on Rust

#81

Earlier quoted context omitted.

> Except where they can't, and those locations aren't terribly consistent. Why aren't they consistent? The Rust type inference is generally very good, and the places where you have to annotate are places where any typechecker would force you to annotate, because the types are simply underconstrained (e.g. the return type of Vec::collect or mem::transmute). > The Rust designers have publicly announced their preference…

> Why aren't they consistent? So, I went back to do a bit of research, and it's gotten better since this first bothered me, my apologies. My beef was with the `let x = vet::Vector::New:: ()` vs `let x: Vec = vec::Vec::New()`. Perhaps not the best way to word it, so consider this objection retracted. :) > the idea that we intentionally made the type inference less powerful than it could have been is totally false Exce…

> Except for function definitions, where the types could be inferred from the function bodies, but are not:

That's an interface boundary, as I mentioned. You would have to write the types in many cases anyway for separate compilation to work. In languages where you have whole-program type inference like ML and Haskell, people frequently end up writing the types for functions because of this issue.

> Plus (and this is more related to the complete lack of implicit type conversions), there are types everywhere in the program. I frequently can't write a number without having to append a type, even when the type has been explicitly defined previously.

This has nothing to do with implicit type conversions, but is rather because numeric literals have no type. It is not a type inference problem; it is just the way that numeric literals are defined.

> let mut s: Vec3 = Vec3{x: 0f64, y: 0f64, z: 0f64, w: 0f64};

That much explicitness is not necessary. It could be written:

    let mut s: Vec3 = Vec3 { x: 0.0, y: 0.0, z: 0.0, w: 0.0 };
Or:

    let mut s = Vec3 { x: 0f64, y: 0.0, z: 0.0, w: 0.0 };

Re: Some notes on Rust

#82
post #67

Earlier quoted context omitted.

You're correct.

Actually, I got curious and tried it out. Turns out Rust didn't optimize the heap case: it used the caller's stack, and only then copied the value to the heap. https://play.rust-lang.org/?code=%23!%5Bfeature(core)%5D%0A%...

Because it would change the semantics of the program. Where heap allocations happen is considered a side effect, and forcing a function to be inline(never) also makes it have unconstrained side effects (in some cases). Those side effects cannot be reordered.

Re: Some notes on Rust

#83

Earlier quoted context omitted.

> References and lifetimes allow you to safely return pointers to stack allocated objects. In C++, you'd have to do this: MyType value; my_function(&value); When returning references, rust uses the lifetimes instead of explicit declarations to figure out where (on the stack) `value` needs to be allocated. OMG, thank you for including this. I spent several months reading every bit of documentation that was available f…

> But I don't know if technical details such as this are high enough on the priority list. There are actual features which still have no documentation. It's hard being a single person trying to keep up with changes from tons of other people, many full time and some community. I may be the person who is most looking forward to Rust being stable...

And I should say, for the record, that you deserve a ton of credit for being a nearly superhuman job. The doc may be lacking, but it would be far worse off without you.

Still, I wish the team/community could find a way to shore up the coverage of this kind of information. I think we've given beginners enough for now, that the focus should shift to "details you need to know about what the compiler does."

Re: Some notes on Rust

#85
post #58

Wow. I wrote that article on LtU last night, after going over there to see what the language theorists were saying about Rust. (And after, for the third time in three weeks, having my Rust code fail to compile because the Rust crowd changed the language again, after the "alpha release" and its claims of stability: http://blog.rust-lang.org/2014/12/12/1.0-Timeline.html ) I wasn't expecting it to be picked up on Hacker…

Not easier than C++? I dunno, C++ looks like a clusterfuck of complicatedness. I'm mostly coming from F#, with some C. Rust's ownership system just makes sense and seems to perfectly answer the questions I have when using C APIs. Rust, for me, looks a lot like what I've wanted when writing performance F#. I'd commit atrocities to have optional ownership in F#. Every time I've fought with the borrow checker, it's beca…

Overall, I think Rust is easier to use than C++ but not easier to write than C++. Writability is a specific facet of usability, which is hurt by strict upfront checks.

Writability is a worthy thing to improve: GHC's -fdefer-type-errors feature is a good example. I hope Rust improves its writability in the future.

Re: Some notes on Rust

#86

Earlier quoted context omitted.

> So I should use `return` except when I shouldn't? This is the cognitive overhead problem I'm talking about. No. Use `return` only when you must . If you want an early return in a function, then you need to use `return`. If you don't need an early return, then don't use `return` at all. I can't remember if this was ever a cognitive load for me personally. I don't think it was.

> I can't remember if this was ever a cognitive load for me personally. I don't think it was. Well, to be fair, it sounds like you're used to semicolons having special meaning (aside from separating expressions) from a previous language. > As for `;`, it's just like Standard ML. `;` is for sequencing expressions. I love it. It's worth remembering that most users of C, C++, Ruby, Java, Python, or whathaveyou are not u…

I'm a C/Python person, and it did take a question on irc for me to get my head around how Rust does it, but now it seems so natural that it's a little irksome to look at some of my Python code :)

Re: Some notes on Rust

#87
post #78

I don't have an account there so I'll comment here: > In particular, allocating a new object and returning a reference to it it from a function is common in C++ but difficult in Rust, because the function doing the allocation doesn't know the expected lifetime of what it returns. This is what boxes are for. A Box is a unique pointer to a value on the heap and can be used without knowing compile-time lifetimes. Refere…

>Unlike C++, 1. Macros from one crate aren't imported into another unless > the user explicitly requests that they be. 2. Macro invocations are > clearly macro invocations. You never have to wonder if something is a > function or a macro. Given the reference to Boost, the author is almost certainly talking about template metaprogramming, not C macros. TMP is obviously a lot more limited in scope than Rust macros, but…

Boost has all kinds of preprocessor macro stuff, like a loop construct that works through recursive includes, and the foreach macro (hopefully obsoleted with C++11).

Re: Some notes on Rust

#88
post #85

Earlier quoted context omitted.

Not easier than C++? I dunno, C++ looks like a clusterfuck of complicatedness. I'm mostly coming from F#, with some C. Rust's ownership system just makes sense and seems to perfectly answer the questions I have when using C APIs. Rust, for me, looks a lot like what I've wanted when writing performance F#. I'd commit atrocities to have optional ownership in F#. Every time I've fought with the borrow checker, it's beca…

Overall, I think Rust is easier to use than C++ but not easier to write than C++. Writability is a specific facet of usability, which is hurt by strict upfront checks. Writability is a worthy thing to improve: GHC's -fdefer-type-errors feature is a good example. I hope Rust improves its writability in the future.

I think just like other languages, writing Rust leads to a familiarity with what the compiler wants. Then you spend more time thinking about design and the problem at hand, and less fighting the compiler. I think Rust will ultimately be easier than C++ to write because while there are tricky concepts to master, there should be much fewer of them than C++ has.

Re: Some notes on Rust

#89
post #67

Earlier quoted context omitted.

You're correct.

Actually, I got curious and tried it out. Turns out Rust didn't optimize the heap case: it used the caller's stack, and only then copied the value to the heap. https://play.rust-lang.org/?code=%23!%5Bfeature(core)%5D%0A%...

That's because of `Box::new`, I'd think. If you use the box keyword, you should get the placement new effect.

Re: Some notes on Rust

#90
post #86

Earlier quoted context omitted.

> I can't remember if this was ever a cognitive load for me personally. I don't think it was. Well, to be fair, it sounds like you're used to semicolons having special meaning (aside from separating expressions) from a previous language. > As for `;`, it's just like Standard ML. `;` is for sequencing expressions. I love it. It's worth remembering that most users of C, C++, Ruby, Java, Python, or whathaveyou are not u…

I'm a C/Python person, and it did take a question on irc for me to get my head around how Rust does it, but now it seems so natural that it's a little irksome to look at some of my Python code :)

Ruby also does this, so if you want that natural feel in your dynamically typed language... ;)
Post reply on HN