Live data from Hacker News

Next Iteration of “The Rust Programming Language” Book

rust-lang.github.io

91–100 of 111 posts

Re: Next Iteration of “The Rust Programming Language” Book

#91

Earlier quoted context omitted.

I think it is. Especially if you keep your code in a public repo, any breaking changes (probably just tweaks as opposed to huge features that break stuff), will probably have a pr filed via cargo. From what I understand, the rust team has scripts that crawls the repos and compiles everything looking for usages of some feature being used that's going to break in the next release, and they will issue a pull request to…

It's more subtle than that. For most things, we guarantee no breakage at all, and we do runs like that (though not against github, but against crates.io) to verify we haven't accidentally broken something. For stuff that we are allowed to change, but might cause breakage, we will try to find stuff and send PRs. But the default and our intention is zero breakage as much as possible, not just "we'll fix it for you". We…

Automatically filed pull requests against my github repo would be amazing!

Actually, you all looking through crates and sending PR's is pretty impressive in itself.

Re: Next Iteration of “The Rust Programming Language” Book

#92
post #73

Earlier quoted context omitted.

Brand new project. I added them by putting the dependencies into the cargo.toml file (with the current version), is that how you're meant to add them or is there some kind of "cargo install" command?

Ah ha! Yeah, so it makes sense that the latest version would need the latest version of the compiler. You could use the previous version and it should still work. Usually, when a project requires a new Rust version, there's a bump to whichever version determines compatibility. (for x.y.z, x if x != and y if x == 0) Given that you said it was breaking, I thought you meant you had a project that suddenly stopped workin…

It makes sense in this specific case, but I do hope it's not a sign of things to come and libraries aren't requiring bleeding edge features.

Re: Next Iteration of “The Rust Programming Language” Book

#93
post #21

Earlier quoted context omitted.

Lifetimes can be confusing as hell, especially declaring them correctly. It looks like section 10.3 in this new book improves things.

As a C++ programmer, I understand ownership and borrowing, but I find the lifetime syntax impenetrable. It clutters the code with annotations that seem like they could be deduced by the compiler. For example, a variable's lifetime is relative to another variable or function. Why must we create a placeholder name like 'a instead of referring to the other variable by name? Take this example from section 10.3: fn longes…

The Rust community prefers explicitness in many cases. We already have lifetime elision for simpler things. Both of these cases in your comment have been extensively discussed and decided against.

The reason why the former is not done is because it makes the signature dependent on the body. This means that changing some code could potentially change the signature of the function, which is the kind of silent magic that folks would prefer to be explicit. Also, as the function gets larger, this is harder to deduce by looking at the code. The current elision rules all operate on the signature, so you only need to look at the signature to figure out the lifetimes, elision or not.

The latter is way more controversial. The reason there is similar; folks want it to be obvious from the type name that it is a borrowing type, and changes to the internals shouldn't magically change the signature without an explicit acknowledgement.

Even type arg lifetime elision was controversial. Currently, in Rust, you can write a function like `fn foo(x: &u8) -> Foo`, where `Foo` is actually `Foo`, and the compiler inserts the lifetimes in the right places. When this was proposed there was a good chance that it would not happen (though as you can see it did happen). So the status quo on lifetime elision is probably not going to change in my opinion, given how hard it was to make the last one happen (of course, you have the "overton window" of acceptable implicitness gradually shifting due to that change, so it might after all)

To me personally, this explicitness is a minor annoyance when dealing with simpler stuff, but is invaluable in codebases making heavier use of lifetimes, like rustc (which avoids reference counting, even though compilers generally need a lot of tricky sharing). And ultimately, I appreciate it even in codebases with fewer lifetimes; I don't like having to peek at a function's code to understand how it's supposed to be used.

Re: Next Iteration of “The Rust Programming Language” Book

#94
post #21

Earlier quoted context omitted.

Lifetimes can be confusing as hell, especially declaring them correctly. It looks like section 10.3 in this new book improves things.

As a C++ programmer, I understand ownership and borrowing, but I find the lifetime syntax impenetrable. It clutters the code with annotations that seem like they could be deduced by the compiler. For example, a variable's lifetime is relative to another variable or function. Why must we create a placeholder name like 'a instead of referring to the other variable by name? Take this example from section 10.3: fn longes…

> For example, a variable's lifetime is relative to another variable or function. Why must we create a placeholder name like 'a instead of referring to the other variable by name?

Because they're different namespaces? &'x refers to the lifetime x, which has no relation to the local variable x, the global x, the type x or the module x.

Re: Next Iteration of “The Rust Programming Language” Book

#95
post #21

Earlier quoted context omitted.

Lifetimes can be confusing as hell, especially declaring them correctly. It looks like section 10.3 in this new book improves things.

As a C++ programmer, I understand ownership and borrowing, but I find the lifetime syntax impenetrable. It clutters the code with annotations that seem like they could be deduced by the compiler. For example, a variable's lifetime is relative to another variable or function. Why must we create a placeholder name like 'a instead of referring to the other variable by name? Take this example from section 10.3: fn longes…

No lifetime parameters can be shorter than the lifetime of the struct itself, and that's part of the so-called WF (well-formed(ness)) rules in Rust (which the compiler tries to make as implicit as possible).

However, that has nothing to do with why you have to have a parameter. The parameter is there to make all instances of App track the actual lifetime, e.g. you can tell between App and App (and in the former case, it can keep the borrow that made the &'foo Config alive for as long as the App sticks around, and if this is longer than the underlying data lives for, you get an "use after free" error).

Combined with function signatures, Rust can track complex interactions without ever looking at callee bodies, and if you're never reusing a lifetime parameter, you get just as much flexibility as if you were passing the references around directly.

This is something that the C++ attempts at tracking scopes and enforcing a set of rules about them, don't seem to have figure out yet. You need a certain amount of annotations to keep the correct mapping, otherwise you just lose information and have to assume every struct that contains a reference may borrow everything that was borrowed at some point and the borrow may have "escaped" into a struct.

You're either too conservative and thus can't apply the rules to prevent iterator invalidation and data races like Rust can with borrows (Cyclone didn't have borrow-checking either IIRC), or you're ignoring an entire subset of UAF bugs waiting to happen.

Even for the purpose of preventing UAF, such an imprecise aliasing-analysis-like conservative system may be too restricting for many real-world usecases, whereas Rust's, ironically, wouldn't be.

Re: Next Iteration of “The Rust Programming Language” Book

#96
post #76

Earlier quoted context omitted.

I've been reading the early access version for a while now, and it is excellent . I hadn't had much luck with the "official" documentation, previously. Jim Blandy's writing is an exemplar for good teaching technique, and this book is shaping up to be the go-to recommendation for learning Rust, in my opinion.

I have been reading it as well. For my taste, it is a bit too verbose. I like to see something along the lines of the K&R book or the GoPL book. I was hoping that "Programming Rust" is such a book, but I was disappointed. And (may be it is just me) I like to see exercises in Programming books.

C an Go are pretty concise languages so they lend themselves to K&R and GoPL. Rust is a big language (like C++) and is still changing quite a bit so I don't think you'll get a similar tome in the near future. (imo)

Re: Next Iteration of “The Rust Programming Language” Book

#97
post #55

Earlier quoted context omitted.

Thanks! I would absolutely love a single webpage version, that would be even better

You can click the "print" button in the upper right hand corner, which gives you http://rust-lang.github.io/book/print.html

Ah - those icons are quite small and subtle. I hadn't noticed them.

Also, while the top right one has a tooltip, the two top left ones don't so you have to click to find out what they do. Always a risky move!

Re: Next Iteration of “The Rust Programming Language” Book

#98
post #21

Earlier quoted context omitted.

Lifetimes can be confusing as hell, especially declaring them correctly. It looks like section 10.3 in this new book improves things.

As a C++ programmer, I understand ownership and borrowing, but I find the lifetime syntax impenetrable. It clutters the code with annotations that seem like they could be deduced by the compiler. For example, a variable's lifetime is relative to another variable or function. Why must we create a placeholder name like 'a instead of referring to the other variable by name? Take this example from section 10.3: fn longes…

I thought the same thing (especially about structs), but after some time with Rust I actually like the explicitness about lifetime rules.

As soon as you are not fighting with lifetimes anymore, it's just a bit more to type. IMHO it actually makes code easier to read, since I don't have to remember a lot of weird rules.

But I have to admit that Rust already has some rules for lifetime elision (e.g. `fn getx(&self) -> &T { &self.x }`. I can only speak for myself but IMHO these rules have a pretty good cost/benefit ratio. For me introducing more rules adds just more cost for diminishing value.

Post reply on HN