-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Emoji based error handling #1565
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
- Feature Name: emoji_based_error_handling | ||
- Start Date: 2016-04-01 | ||
- RFC PR: (leave this empty) | ||
- Rust Issue: (leave this empty) | ||
- RFC Authors: [@dbrgn][DB], [@dns2utf8][SS], [@rnestler][RN] | ||
|
||
|
||
# Summary | ||
[summary]: #summary | ||
|
||
This RFC proposes to implement emoji based error handling in Rust. | ||
|
||
|
||
# Motivation | ||
[motivation]: #motivation | ||
|
||
Emoji have become an universal way of expressing emotions. Error handling in is | ||
generally a very emotional topic in software development. Therefore error | ||
handling and the use of emoji are a perfect match. | ||
|
||
Furthermore, after the introduction of the question mark postfix operator in | ||
[RFC 243][1] (Trait-based exception handling), a lot of people raised concerns | ||
that error handling is not visible enough in the code anymore. Using colorful | ||
emoji to denote error handling would certainly make it obvious that errors are | ||
being handled. | ||
|
||
|
||
# Detailed design | ||
[design]: #detailed-design | ||
|
||
**Description** | ||
|
||
The cornerstones of Rust error handling are two enums: `Result` and `Option`. A | ||
`Result<T, E>` may either be `Success<T>` or `Err(E)` while an `Option(T)` may | ||
be either `Some(T)` or `None`. | ||
|
||
```rust | ||
enum Result<T, E> { | ||
Ok(T), | ||
Err(E), | ||
} | ||
enum Option<T> { | ||
Some(T), | ||
None, | ||
} | ||
``` | ||
|
||
We suggest that these error types are complemented by emoji based alternatives. | ||
|
||
A `Result` is an expression of hope for a certain outcome (:pray:, U+1F64F). If | ||
the operation succeeds, developers party (:beers:, U+1F37B), but sometimes shit | ||
happens (:poop:, U+1F4A9). | ||
|
||
```rust | ||
enum 🙏<T, E> { | ||
🍻<T>, | ||
💩<E>, | ||
} | ||
``` | ||
|
||
On the other hand, an `Option` is an expression of uncertainty (:interrobang:, | ||
U+203D). Something might be there (:raising_hand:, U+1F64B) or it might not be | ||
(:x:, U+274C). | ||
|
||
```rust | ||
enum ‽<T> { | ||
🙋<T>, | ||
❌, | ||
} | ||
``` | ||
|
||
**Matching** | ||
|
||
These emoji can be matched as usual: | ||
|
||
```rust | ||
fn i_am_a_teapot(which_kind: ‽<TeaType>) -> 🙏<Tea, String> { | ||
match which_kind { | ||
🙋(kind) => 🍻(kind.brew()), | ||
❌ => 💩("Not specified which kind of tea to brew."), | ||
} | ||
} | ||
``` | ||
|
||
**Unwrapping and Macros** | ||
|
||
Another often used error handling mechanism is the `try!` macro. We suggest | ||
using the :muscle: emoji to bring across the notion of strength or trust. Yes | ||
we try! | ||
|
||
When the developer is too lazy to do proper error handling, he/she may also use | ||
the `unwrap()` method. We suggest replacing it with the see-no-evil emoji | ||
(:see_no_evil:). | ||
|
||
Last but not least, when all else fails, code may panic (:scream:). | ||
|
||
```rust | ||
if let 🙋(coffee) = brew() { | ||
println!("Drinking {} coffee", coffee.rate_taste().🙈()); | ||
💪!(coffee.drink()); | ||
} else { | ||
😱!("406 - WE'RE OUT OF COFFEE!!1"); | ||
} | ||
``` | ||
|
||
**Feature Gate** | ||
|
||
As with other newly proposed features, we propose adding a feature gate for emojified error handling: | ||
|
||
```rust | ||
#[feature(emojification)] | ||
``` | ||
|
||
**Implementation** | ||
|
||
The Rust grammar already fully supports UTF8. There are two ways to implement this: | ||
|
||
- Modify the `IDENTIFIER` grammar to include unicode characters. Currently | ||
identifiers may only contain ASCII letters and underscores. | ||
- Implement a syntax extension that operates on the token tree and that | ||
replaces all occurrences of certain emoji with their regular ASCII | ||
counterparts. | ||
|
||
|
||
# Drawbacks | ||
[drawbacks]: #drawbacks | ||
|
||
None, although the proposal might seem less convincing on other days of the year. | ||
|
||
|
||
# Alternatives | ||
[alternatives]: #alternatives | ||
|
||
Alternative Result emoji choices have been suggested: | ||
|
||
- Proposal (:ring:) with success (:heart:) or no success (:broken_heart:) | ||
- Fear (:fearful:) with yay (:sparkles:) or nay (:skull:) | ||
|
||
|
||
|
||
# Unresolved questions | ||
[unresolved]: #unresolved-questions | ||
|
||
- Not all commonly used fonts and text editors offer full support of all | ||
required Unicode characters. But that problem could be resolved trivially | ||
by developing our own fully featured `rust.ttf` font and `rustty` terminal | ||
emulator. | ||
- So far, a syntax extension to implement support for the proposed features has | ||
not yet been written and published. | ||
|
||
|
||
|
||
[1]: https://github.com/rust-lang/rfcs/pull/243 | ||
[DB]: https://github.com/dbrgn | ||
[SS]: https://github.com/dns2utf8 | ||
[RN]: https://github.com/rnestler |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😱⚠️ These should be
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😱!()