diff options
| author | bors <bors@rust-lang.org> | 2014-01-21 15:56:16 -0800 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-01-21 15:56:16 -0800 |
| commit | 918a7314a8d49d870ff95f8ed6c7bdc5895138c9 (patch) | |
| tree | fcd89f5349850b34b6ed3c7fd7b04ad421705db1 /src/rustllvm/RustWrapper.cpp | |
| parent | 505572b3f830c8f5140efaaf2adf8293e29b0db9 (diff) | |
| parent | ec422d70c3b10974b81eac6988fc5b3fa6ce60bc (diff) | |
| download | rust-918a7314a8d49d870ff95f8ed6c7bdc5895138c9.tar.gz rust-918a7314a8d49d870ff95f8ed6c7bdc5895138c9.zip | |
auto merge of #11129 : SimonSapin/rust/foo-vs-foo_opt, r=alexcrichton
[On 2013-12-06, I wrote to the rust-dev mailing list](https://mail.mozilla.org/pipermail/rust-dev/2013-December/007263.html): > Subject: Let’s avoid having both foo() and foo_opt() > > We have some functions and methods such as [std::str::from_utf8](http://static.rust-lang.org/doc/master/std/str/fn.from_utf8.html) that may succeed and give a result, or fail when the input is invalid. > > 1. Sometimes we assume the input is valid and don’t want to deal with the error case. Task failure works nicely. > > 2. Sometimes we do want to do something different on invalid input, so returning an `Option<T>` works best. > > And so we end up with both `from_utf8` and `from_utf8`. This particular case is worse because we also have `from_utf8_owned` and `from_utf8_owned_opt`, to cover everything. > > Multiplying names like this is just not good design. I’d like to reduce this pattern. > > Getting behavior 1. when you have 2. is easy: just call `.unwrap()` on the Option. I think we should rename every `foo_opt()` function or method to just `foo`, remove the old `foo()` behavior, and tell people (through documentation) to use `foo().unwrap()` if they want it back? > > The downsides are that unwrap is more verbose and gives less helpful error messages on task failure. But I think it’s worth it. The email discussion has gone around long enough. Let’s discuss a concrete proposal. For the following functions or methods, I removed `foo` (that caused task failure) and renamed `foo_opt` (that returns `Option`) to just `foo`. Vector methods: * `get_opt` (rename only, `get` did not exist as it would have been just `[]`) * `head_opt` * `last_opt` * `pop_opt` * `shift_opt` * `remove_opt` `std::path::BytesContainer` method: * `container_as_str_opt` `std::str` functions: * `from_utf8_opt` * `from_utf8_owned_opt` (also remove the now unused `not_utf8` condition) Is there something else that should recieve the same treatement? I did not rename `recv_opt` on channels based on @brson’s [feedback](https://mail.mozilla.org/pipermail/rust-dev/2013-December/007270.html). Feel free to pick only some of these commits.
Diffstat (limited to 'src/rustllvm/RustWrapper.cpp')
0 files changed, 0 insertions, 0 deletions
