News for hackers. Stuff that matters.
Re:Announcing Rust 1.14 by bbatha on Thursday December 22, 2016 @02:57PM (#13239879)
When the carrier trait lands this becomes:

    let id = node.parent()?
                 .parent()?
                 .data_get("id")?
                 .parse::<usize>()
                 .ok()?;
I'd also expect that someone will write higher level libraries so that you aren't doing raw DOM manipulation. A rust vdom wasm library would probably be blazing fast.
Re:Announcing Rust 1.14 by killercup on Thursday December 22, 2016 @03:28PM (#13240106)
> A rust vdom wasm library would probably be blazing fast.

Even regardless of performance, it would be quite nice to have! I've been meaning[1] to build a small prototype to do something clever[2] with it, but didn't have the time yet. Feel free to steal these ideas :)

[1]: https://scribbles.pascalhertleif.de/impl-virtual-dom-cli-lib... [2]: https://scribbles.pascalhertleif.de/rich-diffs-of-rendered-h...

Re:Announcing Rust 1.14 by topspin on Thursday December 22, 2016 @03:33PM (#13240146)
Even without the ? sugar I don't see what's so offensive about this; the least little formatting effort produces:

    let id = node.parent().unwrap()
                 .parent().unwrap()
                 .data_get("id").unwrap()
                 .parse::<usize>().unwrap();
If there is something horrible about that I don't see it.
Re:Announcing Rust 1.14 by stymaar on Thursday December 22, 2016 @05:48PM (#13241098)
Unwrap will panic if no parent is found, whereas the `?` operator allows for a clean handling of this situation.

Dealing with this case properly without using a single `?`, gets really ugly with a lot of nested

    if let Some(parent) = node.parent() {
Re:Announcing Rust 1.14 by ballpointcarrot on Thursday December 22, 2016 @03:51PM (#13240283)
Some people prefer their languages to be more concise, and the safety of the the option objects (and the requirement of the unwrap() calls in the function chain) feels unwieldy. Moreover, as the unwrap() calls could panic if there's no attribute, the more complete handling of it is even longer (match calls and following the successful path).

This could be a function to isolate just the attribute you need, but seeing the example as it is presented can be off-putting from people used to scripting languages like ruby/python, which are more concise.

Re:Announcing Rust 1.14 by 102030485868 on Thursday December 22, 2016 @03:42PM (#13240213)
It hurts to type sometimes. Typing at work isn't really an issue since I have an ergonomic keyboard, but big side projects can sometimes hurt.

? is far easier and faster to type than .unwrap().

So no, there's nothing horrible that I see, there is something horrible that I feel though.

Re:Announcing Rust 1.14 by oblio on Thursday December 22, 2016 @03:49PM (#13240268)
> If there is something horrible about that I don't see it.

Isn't unwrap():

a) boilerplate

b) repetitive?

Re:Announcing Rust 1.14 by steveklabnik on Thursday December 22, 2016 @03:52PM (#13240295)
It's boilerplate in a certain sense. Those are all points where what you've written might not work. Rust makes you deal with possible problems _somehow_. Specifically, this is a replacement for null. If you legitimately don't care, then it can feel boilerplate-y, but it also lets you start by not having to care, and then searching for unwrap and replacing it with better handling.

In other words, it's boilerplate here because this particular operation has many possible failure modes, and Rust is pointing those out to you.

It's repetitive in this particular instance, but doesn't have to be in general.

Re:Announcing Rust 1.14 by stymaar on Thursday December 22, 2016 @05:57PM (#13241158)
c) a bad practice since it will make your program crash is a node has no parent.

if the node always having a parent is a invariant of your application, you should use `expect` with a clear error message when the invariant is broken.

if your node can have no parents then you want to handle this case explicitly with a `if let Some(parent) = node.parent() {` pattern.

Re:Announcing Rust 1.14 by leeoniya on Thursday December 22, 2016 @03:05PM (#13239933)
> A rust vdom wasm library would probably be blazing fast.

Most of the cost of vdom is the resulting DOM ops and reflow/restyle the browser needs to do. It may be faster than the fastest today, but you're unlikely to see any kind of performance leap or even anything noticeable.

Re:Announcing Rust 1.14 by lobster_johnson on Thursday December 22, 2016 @03:20PM (#13240041)
The "?" operator looks like a more specialized, error/success-specific version of monads. Has there been any discussion about generalizing everything into monad-style chaining operators?

I see that there is some discussion here [1], including a suggestion to add a Haskell-style "do" block. But that's just one guy's blog post.

[1] https://m4rw3r.github.io/rust-questionmark-operator.

Re:Announcing Rust 1.14 by steveklabnik on Thursday December 22, 2016 @03:23PM (#13240075)
Yes, that was endlessly discussed as part of all of this. The TL;DR is: it's not simple. ? is very straightforward and helps people out a lot today. So if and when (and it is a big if) Rust ever gets do notation, this might be a little redundant, but blocking one of people's largest pain points today is worth the (possible) little bit of redundancy.
Re:Announcing Rust 1.14 by lobster_johnson on Thursday December 22, 2016 @04:36PM (#13240597)
Thanks, that makes perfect sense. I haven't followed the internal discussion at all.

It sounds like there are some that would like to move Rust in the direction of becoming more Haskell/ML-like (which is to say more purely functional) rather than the current balance between imperative and functional? Is there any internal tension in that regard?

Re:Announcing Rust 1.14 by steveklabnik on Thursday December 22, 2016 @05:03PM (#13240775)
It's not even a philosophical difference, really, there are technical objections that would have to be addressed somehow before it would even be possible, let alone figure out if it's a feature that's desired. These involve things like "it's still unclear if HKT is going to end up in Rust or not, and how", which is a pre-requirement, as just one example.
Re:Announcing Rust 1.14 by mathw on Friday December 23, 2016 @03:32AM (#13243678)
I believe one of the biggest obstacles to a general monad system in Rust is that the type system can't actually handle it at the moment - it requires higher-kinded types, which may or may not ever actually be added to the language.
Re:Announcing Rust 1.14 by GolDDranks on Friday December 23, 2016 @05:31AM (#13244069)
There's another problem too: a monad trait would unify types behind a monadic interface, but many things that in Haskell are types, are traits in Rust. This is because Rust requires a single type to have uniform memory representation and to be statically dispatchable (save for trait objects). So in Rust, there is not just an "iterator type", but multiple types that have the Iterator trait. The same goes for Future trait.

This leads to a situation where, if there were to be a monad trait, that trait should abstract over not only types, but another traits generically.

Not to speak about some other hurdles, like lifetimes. The design space is inherently more convoluted than in languages with boxed, possibly dynamically dispatched types. It may be possible, but it's not easy, and we can't copy the monads straightforwardly from Haskell or Scala.

Re:Announcing Rust 1.14 by mathw on Friday December 23, 2016 @06:06AM (#13244181)
Good point! A whole other set of things also need to be hoisted to make this work.
Re:Announcing Rust 1.14 by tatterdemalion on Thursday December 22, 2016 @03:34PM (#13240148)
The semantics of ? are different from monadic bind and fit better to Rust's language context of strictness, imperativeness, and mutability than Monad (which is a problematic type class in Rust for some separate reasons).
Re:Announcing Rust 1.14 by libria on Thursday December 22, 2016 @03:04PM (#13239928)
Swell! I was hoping that existed in this language. The rest of the code looks concise FWIW, https://github.com/tcr/rust-todomvc/blob/master/src/main.rs
Re:Announcing Rust 1.14 by steveklabnik on Thursday December 22, 2016 @03:06PM (#13239948)
Small note, we don't _technically have to stabilize Carrier to land this, just implement it for Option. (yay standard library types) However, ? for Option is a bit controversial, so we'll see...
Re:Announcing Rust 1.14 by masklinn on Thursday December 22, 2016 @04:52PM (#13240694)
> However, ? for Option is a bit controversial

Because people wouldn't expect it to return due to behaviour of existing languages yet that's what it does in Rust?

Re:Announcing Rust 1.14 by Rusky on Thursday December 22, 2016 @04:59PM (#13240747)
More because Option is not really intended to handle errors while Result and ? are.
Re:Announcing Rust 1.14 by steveklabnik on Thursday December 22, 2016 @05:07PM (#13240803)
Yes, that's correct. If we make ? go to more than just result, you could implement it for any type, and it's not totally clear that changing it from "error handling" to "general control flow" is a good idea.

Many are in favor of doing it, though. I'm personally against it.

Re:Announcing Rust 1.14 by int_19h on Thursday December 22, 2016 @08:16PM (#13242018)
Whether it's ? or something else, having a very concise form of syntactic sugar to unwrap option types is desirable. Most languages that don't have it, eventually acquire it due to demand.