-
Notifications
You must be signed in to change notification settings - Fork 433
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
Rng renames: gen_ → random_ #1505
Conversation
|
||
/// Alias for [`Rng::random_range`]. | ||
#[inline] | ||
#[deprecated(since = "0.9.0", note = "Renamed to `random_range`")] |
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.
Maybe it's better to do a deprecating backport and release in the v0.8 branch and remove these methods completely in v0.9?
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.
I don't think we should add a #[deprecated]
notice in a patch release because (a) it may break some builds (https://doc.rust-lang.org/cargo/reference/semver.html#new-lints) and (b) it effectively forces users who don't want to see a warning to update their code just because they updated to the next patch version.
Since the next release is a breaking release, we could just not add these #[deprecated]
fn wrappers, but they potentially ease migration and I don't see much harm in leaving them in until 1.0 (or 0.10).
/// ``` | ||
/// | ||
/// [`Bernoulli`]: distr::Bernoulli | ||
#[inline] | ||
#[track_caller] | ||
fn gen_ratio(&mut self, numerator: u32, denominator: u32) -> bool { | ||
fn random_ratio(&mut self, numerator: u32, denominator: u32) -> bool { |
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.
I think this name could be misleading. It sounds as if it generates a "random ratio". But I don't have a better proposal than much longer random_bool_with_ratio
or the generic argument proposal, so I guess it's fine.
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.
Is code like this confusing? I don't think it's particularly confusing:
if rng.random_ratio(1, 100) {
do_something();
}
An alternative is that we just remove the method and tell people to use Bernoulli::from_ratio(n, d).unwrap().sample(&mut rng)
, but I don't see a real reason to remove this little utility fn.
I don't really like the new name. I would prefer something like I agree that |
CHANGELOG.md
entrySummary
This appears to be the conclusion of #1503:
Opinion
My personal feeling is that this is a poor choice. We recently renamed
rand::distributions
torand::distr
because the latter was easier to type and consistent withrand_distr
(see #1381). This achieves some level of consistency (excepting thatrandom_bool
describes its output while otherrandom*
methods describe their input), but is not concise.