On 12/22/2016 02:22 AM, Eric Rahm wrote:
> The key point for me is that we're hiding the return. I'm fine with the
> more verbose
> explicitly-return-and-make-it-easier-for-the-reviewer-to-call-out-issues
> form. I understand this is going to have differing opinions -- I think
> there's merit to more concise code -- but for the things I look at I much
> prefer an explicit return.
It's a fair cop. I'm still about ---> <---- close to thinking the macro's
hidden early-return is just bad (and very nearly Result too is just bad,
because the one without the other is pretty small-potatoes), and the whole idea
should go.
To me, the key is we're not designing anew. We're implementing an established
idiom from another language. It's a fresh, new language not everyone is
familiar with. But it's also a language that's *our* language as near as
anything can be, with lots of our own input on it, with lots of us working with
it, with our having shipped Firefox depending on it, and with (at the time) its
foreseeably becoming a Firefox build requirement (and now *is* one).
Against that backdrop, MOZ_TRY is quite similar to try!, and developers who
have seen even small amounts of Rust will have seen try!. The naming
similarity will suggest its sense. And the documentation in Result.h should
fully clarify that meaning. (Incidentally: questions/comments about
functionality should probably funnel into MFBT bugs to improve the
documentation. Asking questions here, or on IRC, or wherever, does not scale.
Clear documentation in headers does.)
That said, these were my conclusions over the several months mozilla::Result
was percolating. Only just this week I learned Rust has a new postfix ?
operator, that does much the same thing as try!, including "hiding" an early
return:
let file = std::fs::File::create("foobar.txt")?;
file.write_all(format!("line 1").as_bytes())?;
file.write_all(format!("line 2").as_bytes())?;
file.write_all(format!("line 3").as_bytes())?;
Mozilla's Rust compiler requirement is sufficient to ensure support for this
operator. So I would expect most people writing Rust, and most people writing
Rust in Gecko, will decreasingly see try! in real-world code.
Given that, will try! remain enough of a Rust idiom for it and MOZ_TRY to
symbiotically reinforce each other? I don't know. If there's no real
precedent, is MOZ_TRY justifiable? I don't know. Maybe people teaching Rust
will travel through try! before reaching ?, and so try! remains a (diminished)
precedent. Or maybe they won't. Suffice to say that a newly-discovered
operator a few days later isn't enough to convince me to rethink this so
drastically.
Jeff
_______________________________________________
dev-platform mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-platform