# Bikeshed: A consise verb for the \`?\` operator

**URL:** <https://internals.rust-lang.org/t/bikeshed-a-consise-verb-for-the-operator/7289>\
**Category:** Uncategorized\
**Created:** [April 11, 2018, 7:20am UTC](https://internals.rust-lang.org/t/bikeshed-a-consise-verb-for-the-operator/7289 "2018-04-11T07:20:30Z")\
**Posts on this page:** 20\
**Page:** 4

<div class="post-metadata">

**Author:** ![steven099](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/steven099/32/3871_2.png) [@steven099](https://internals.rust-lang.org/u/steven099)\
**Post date:** [May 14, 2018, 10:40pm UTC](https://internals.rust-lang.org/t/bikeshed-a-consise-verb-for-the-operator/7289/61 "2018-05-14T22:40:00Z")

</div>

> [@uberjay](#):
>
> (imagine, for the purpose of this experiment that the `check` function could actually return from the enclosing scope. Perhaps if traits could implement macros?)

Rust currently uses a trait called [`Try`](https://doc.rust-lang.org/stable/std/ops/trait.Try.html) (the name coming from calling `?` 'try' after the `try!(...)` macro). It really only abstracts over success and failure, with the compiler generating the necessary control flow. It could probably be called "check" if that was what we decided to call `?`.

Member macros is an interesting idea, though problematic since it requires type resolution to happen before code generation, which might in turn affect type resolution etc... Another approach would be to have a return type which encapsulates imperative effects, like `return`, `break`, etc... So you could escape a block of code and return it (pseudocode):

```rust
impl<T, E> Check<T> for Result<T, E> {
    fn check<C, RT, RE>(self) -> impl Command<T, C>
    where 
        C: ImperativeContext<Return=Result<RT, RE>>,
        E: Into<RE>,
    {
        escape {
            match self {
                Err(e) => return Err(e.into()),
                Ok(v) => v
            }
        }
    }
}

```

and then `run` it in a caller. The names and overall design are obviously just placeholders to communicate the idea.

---

<div class="post-metadata">

**Author:** ![MajorBreakfast](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/majorbreakfast/32/4015_2.png) [@MajorBreakfast](https://internals.rust-lang.org/u/MajorBreakfast)\
**Post date:** [May 14, 2018, 11:24pm UTC](https://internals.rust-lang.org/t/bikeshed-a-consise-verb-for-the-operator/7289/62 "2018-05-14T23:24:56Z")

</div>

How about making finding an official name for this a goal for Rust 2018? 😁

I just read through the thread. Here is my personal short list:

- check
- maybe
- try

---

<div class="post-metadata">

**Author:** ![Centril](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/centril/32/3334_2.png) [@Centril](https://internals.rust-lang.org/u/Centril)\
**Post date:** [May 15, 2018, 12:07am UTC](https://internals.rust-lang.org/t/bikeshed-a-consise-verb-for-the-operator/7289/63 "2018-05-15T00:07:34Z")

</div>

> [@MajorBreakfast](#):
>
> How about making finding an official name for this a goal for Rust 2018? 😁

..Must ..Resist .._Urge_ ..To ..Bikeshed.. 😓

---

<div class="post-metadata">

**Author:** ![Soni](https://avatars.discourse-cdn.com/v4/letter/s/a3d4f5/32.png) [@Soni](https://internals.rust-lang.org/u/Soni)\
**Post date:** [May 17, 2018, 3:38am UTC](https://internals.rust-lang.org/t/bikeshed-a-consise-verb-for-the-operator/7289/64 "2018-05-17T03:38:24Z")

</div>

I like “propagate” because it’s **not** about exception/error handling.

It’s about propagation:

```rust
fn whelp() -> Option<X> {
   a?.b?.c?.d?.e // assuming e is an Option<X>. otherwise put an .into() on it
}

```

---

<div class="post-metadata">

**Author:** ![repax](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/repax/32/1342_2.png) [@repax](https://internals.rust-lang.org/u/repax)\
**Post date:** [May 17, 2018, 5:06am UTC](https://internals.rust-lang.org/t/bikeshed-a-consise-verb-for-the-operator/7289/65 "2018-05-17T05:06:50Z")

</div>

I don’t know… You can say that `whelp` _failed_ to produce an `X`. I see them as conditional failure points.

The beauty of `?` is that it’s quick and easy to find the possible points of failure of a `fn` without them being distracting.

---

<div class="post-metadata">

**Author:** ![illustrious-you](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/illustrious-you/32/3960_2.png) [@illustrious-you](https://internals.rust-lang.org/u/illustrious-you)\
**Post date:** [June 1, 2018, 11:48am UTC](https://internals.rust-lang.org/t/bikeshed-a-consise-verb-for-the-operator/7289/66 "2018-06-01T11:48:26Z")

</div>

I was reading the [PreRFC for catching functions](https://internals.rust-lang.org/t/pre-rfc-catching-functions/6505/145) when a link posted by @scottmcm caught my eye: [Exceptional Syntax - Microsoft Reserarch](https://www.microsoft.com/en-us/research/publication/exceptional-syntax/)

The paper called `?` “unless”. Though it’s not a verb–it’s a conjunction–it presents a concise word that’s a reasonable shorthand of the control flow: “continue `unless` {fn} returns an error”.

---

<div class="post-metadata">

**Author:** ![lordan](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/lordan/32/2107_2.png) [@lordan](https://internals.rust-lang.org/u/lordan)\
**Post date:** [June 2, 2018, 2:09pm UTC](https://internals.rust-lang.org/t/bikeshed-a-consise-verb-for-the-operator/7289/67 "2018-06-02T14:09:19Z")

</div>

… did someone say “bikeshed”? 😃 Anyway, this would be my suggestions:

- `ensure`, or conversely:
- `diverge`

---

<div class="post-metadata">

**Author:** ![IsaacWoods](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/isaacwoods/32/4767_2.png) [@IsaacWoods](https://internals.rust-lang.org/u/IsaacWoods)\
**Post date:** [June 3, 2018, 11:17am UTC](https://internals.rust-lang.org/t/bikeshed-a-consise-verb-for-the-operator/7289/68 "2018-06-03T11:17:07Z")

</div>

> [@lordan](#):
>
> `diverge`

Hmm, since a function of type `fn(...) -> !` is known as a diverging function already, this doesn't seem like a great choice

---

<div class="post-metadata">

**Author:** ![lordan](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/lordan/32/2107_2.png) [@lordan](https://internals.rust-lang.org/u/lordan)\
**Post date:** [June 3, 2018, 11:58am UTC](https://internals.rust-lang.org/t/bikeshed-a-consise-verb-for-the-operator/7289/69 "2018-06-03T11:58:33Z")

</div>

Good point! In that case I’d change my suggestion to

- `bail`

as a suggestion if we want to emphasize the “aborting” nature.

---

<div class="post-metadata">

**Author:** ![scottmcm](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/scottmcm/32/2355_2.png) [@scottmcm](https://internals.rust-lang.org/u/scottmcm)\
**Post date:** [June 3, 2018, 4:14pm UTC](https://internals.rust-lang.org/t/bikeshed-a-consise-verb-for-the-operator/7289/70 "2018-06-03T16:14:26Z")

</div>

> [@illustrious-you](#):
>
> The paper called `?` “unless”

The paper is in SML, which has implicitly-propagated exceptions, so _doesn't contain a name for `?` at all_, as the operator doesn't exist. It uses `unless` for what's basically `catch`. Its

```rust
let x = A;
in B(x)
unless C => D

```

is essentially

```rust
match try { A } {
    Ok(x) => B(x),
    Err(C) => D,
}

```

Also, I think `.foo()?.bar()` reads poorly as "unless", since you get "foo unless bar", which grammatically I would interpret very differently.

> [@lordan](#):
>
> In that case I’d change my suggestion to `bail`

`bail` is what `failure` is currently using for `throw`: [failure::bail - Rust](https://docs.rs/failure/0.1.1/failure/macro.bail.html)

---

<div class="post-metadata">

**Author:** ![xfix](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/xfix/32/2726_2.png) [@xfix](https://internals.rust-lang.org/u/xfix)\
**Post date:** [June 3, 2018, 7:23pm UTC](https://internals.rust-lang.org/t/bikeshed-a-consise-verb-for-the-operator/7289/71 "2018-06-03T19:23:43Z")

</div>

I usually call it “question mark operator”, and in fact if you try searching for “question mark operator rust” with your favorite search engine, you will find results for it.

An unoriginal name, sure, but nobody suggested it, and I would wager a guess that most Rust programmers would quickly figure out what “question mark operator” means when seeing somebody use this name.

---

<div class="post-metadata">

**Author:** ![illustrious-you](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/illustrious-you/32/3960_2.png) [@illustrious-you](https://internals.rust-lang.org/u/illustrious-you)\
**Post date:** [June 4, 2018, 2:30pm UTC](https://internals.rust-lang.org/t/bikeshed-a-consise-verb-for-the-operator/7289/72 "2018-06-04T14:30:47Z")

</div>

> [@scottmcm](#):
>
> Also, I think `.foo()?.bar()` reads poorly as “unless”, since you get “foo unless bar”, which grammatically I would interpret very differently.

I agree, reading the code and substituting "unless" doesn't work. Perhaps the key insight is that we should consider conjunctions in addition to verbs.

- So
- Thus
- Therefore
- Ergo
- Hence
- Consequently

"Ergo" has a punny quality to it that might serve as a useful mnemonic -- "on `Err` go".

(Conicidentally, "ergo-" is also [a combining form of "ergot"](http://www.dictionary.com/browse/ergo). Both [ergot](https://en.wikipedia.org/wiki/Ergot) and [rust](https://en.wikipedia.org/wiki/Rust_(fungus)) are fungal plant diseases.)

---

<div class="post-metadata">

**Author:** ![Centril](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/centril/32/3334_2.png) [@Centril](https://internals.rust-lang.org/u/Centril)\
**Post date:** [June 4, 2018, 6:13pm UTC](https://internals.rust-lang.org/t/bikeshed-a-consise-verb-for-the-operator/7289/73 "2018-06-04T18:13:36Z")

</div>

If I'd read `foo.bar()?.baz()?.biz()?.buz()` out loud I'd say:

> "foo, _then maybe_ bar, _then maybe_ baz, _then maybe_ biz, _then maybe_ buz."

or just (pretending that `?` isn't there..):

> "foo, _then_ bar, _then_ baz, \*then biz, _then_ buz"

But I think so far the best proposals have been:

- rethrow (which is _exactly_ what it does, it matches the operational semantics perfectly).
- propagate
- bubble

In conclusion, I think it should be called `rethrow` because:

```rust
expr? == match expr.into_result() { Ok(o) => o, Err(e) => throw!(e); }

```

---

<div class="post-metadata">

**Author:** ![MajorBreakfast](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/majorbreakfast/32/4015_2.png) [@MajorBreakfast](https://internals.rust-lang.org/u/MajorBreakfast)\
**Post date:** [June 4, 2018, 6:29pm UTC](https://internals.rust-lang.org/t/bikeshed-a-consise-verb-for-the-operator/7289/74 "2018-06-04T18:29:26Z")

</div>

I think “rethrow”, “propagate” and “bubble” don’t capture the conditionality aspect enough. “maybe” and “check” capture this aspect because these words suggest that _it could go both ways_.

---

<div class="post-metadata">

**Author:** ![Centril](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/centril/32/3334_2.png) [@Centril](https://internals.rust-lang.org/u/Centril)\
**Post date:** [June 4, 2018, 6:44pm UTC](https://internals.rust-lang.org/t/bikeshed-a-consise-verb-for-the-operator/7289/75 "2018-06-04T18:44:51Z")

</div>

I agree with you that it doesn’t capture that aspect in the word itself; however, I think it is sufficiently implied from the context it is used in and the symbol `?` itself.

On the other hand `maybe` and `check` do not say what happen on “nothing” or “failure”. If you want to be fully unambiguous, I’d say: `maybe rethrow`, but that is a mouthful. 😉

```rust
     foo, then maybe rethrow,
then bar, then maybe rethrow,
then baz, then maybe rethrow,
then biz, then maybe rethrow,
then buz

```

EDIT: if you want a short word, you will invariably not capture some aspect of the full operational semantics.

---

<div class="post-metadata">

**Author:** ![MajorBreakfast](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/majorbreakfast/32/4015_2.png) [@MajorBreakfast](https://internals.rust-lang.org/u/MajorBreakfast)\
**Post date:** [June 4, 2018, 7:17pm UTC](https://internals.rust-lang.org/t/bikeshed-a-consise-verb-for-the-operator/7289/76 "2018-06-04T19:17:12Z")

</div>

I think that the check aspect should be reflected in the name because it decides what happens next. There are of course only two options: The result is ok or there’s an error.

Throwing only happens in case there is an error: The “re” in “rethrow” does not imply that it only throws if there was an error. Instead the word suggests that it assumes there to be an error which it can throw again.

I think the name should be a single word. I agree with you that it this will be not enough to describe its meaning fully. To me the checking which happens first and decides what happens next should be reflected in the name.

Some functions that return a result start with the `try_` prefix. It makes sense to “check” after you “try” something. Same argument works for “maybe” as well: You “try” something and “maybe” it works. Both words are also sufficiently rarely used to make them practical.

Edit: And both of these words also fit nicely to the operator’s symbol the “?”.

---

<div class="post-metadata">

**Author:** ![anatol1234](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/anatol1234/32/4226_2.png) [@anatol1234](https://internals.rust-lang.org/u/anatol1234)\
**Post date:** [June 4, 2018, 10:08pm UTC](https://internals.rust-lang.org/t/bikeshed-a-consise-verb-for-the-operator/7289/77 "2018-06-04T22:08:40Z")

</div>

I am in favor of taking a turbofish-approach for the `?` operator. The behaviour of this operator apparently is just slightly too complex to capture it with a single consise verb. Moreover, turbofish has already opened up the opportunity for a goofy naming scheme. I would even go a step further and propose to utilize the [mnemonic link system](https://en.wikipedia.org/wiki/Mnemonic_link_system) (Mnemonics are frequently used in marketing). The mnemonic link system is an effective method for remembering lists of things or sequences of actions, which may also contain branches.

> For example, when memorizing the list (dog, envelope, thirteen, yarn, window), one could create a story about a "dog stuck in an envelope, mailed to an unlucky thirteen black cat playing with yarn by the window". It is argued that the story would be easier to remember than the list itself.

The behaviour of `?` could be translated to a story using this method and finally be linked to a single word. The rationale is this: It does not really matter if the word itself does not capture any aspect of `?` at all. A user has to look up the exact meaning at least once the first time he comes across a `?` anyway. Whatever information he finds when looking up the meaning of `?` should establish a strong long-term link between `?` and the exact behaviour of `?`.

Here is an example based on a fairy tale:

- `Cinderella` - _"The good ones go into the pot, the bad ones go into your crop"_

The beautiful thing about `Cinderella` is that it also captures the aspect of the `From::from` function being applied in the error case: When picking up a lentil (`Result`) a pigeon (`?`) must consider two options. If the lentil is a good one (`Ok`), the pigeon simply puts it into the pot (evaluates to the wrapped value). However, if the lentil happens to be a bad one (`Err`), the pigeon eats it, digests it (`from`) and finally "returns" it. Also the silhouette of a pigeon kind of resembles a questionmark.

---

<div class="post-metadata">

**Author:** ![scottmcm](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/scottmcm/32/2355_2.png) [@scottmcm](https://internals.rust-lang.org/u/scottmcm)\
**Post date:** [June 5, 2018, 7:40am UTC](https://internals.rust-lang.org/t/bikeshed-a-consise-verb-for-the-operator/7289/78 "2018-06-05T07:40:56Z")

</div>

> [@xfix](#):
>
> I usually call it “question mark operator”, and in fact if you try searching for “question mark operator rust” with your favorite search engine, you will find results for it.
> 
> An unoriginal name, sure, but nobody suggested it

Note that the first post in this thread references that name:

> [@scottmcm](#):
>
> So I guess the official name is the “explicit exception propagation operator”, but that’s a bit of a mouthful and a poor trait name.

---

<div class="post-metadata">

**Author:** ![illustrious-you](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/illustrious-you/32/3960_2.png) [@illustrious-you](https://internals.rust-lang.org/u/illustrious-you)\
**Post date:** [June 5, 2018, 12:14pm UTC](https://internals.rust-lang.org/t/bikeshed-a-consise-verb-for-the-operator/7289/79 "2018-06-05T12:14:15Z")

</div>

> [@Centril](#):
>
> If I’d read `foo.bar()?.baz()?.biz()?.buz()` out loud I’d say:
> 
> > “foo, _then maybe_ bar, _then maybe_ baz, _then maybe_ biz, _then maybe_ buz.”

If, when reading `?`, you reach for conjunctions (then) and other adverbs (maybe), then why identify it with a verb?

---

<div class="post-metadata">

**Author:** ![Centril](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/centril/32/3334_2.png) [@Centril](https://internals.rust-lang.org/u/Centril)\
**Post date:** [June 5, 2018, 3:05pm UTC](https://internals.rust-lang.org/t/bikeshed-a-consise-verb-for-the-operator/7289/80 "2018-06-05T15:05:49Z")

</div>

`then` stands for function application here.

[Previous page](https://internals.rust-lang.org/t/bikeshed-a-consise-verb-for-the-operator/7289.md?page=3)

[Next page](https://internals.rust-lang.org/t/bikeshed-a-consise-verb-for-the-operator/7289.md?page=5)
