Skip to content

Rename thread_rng to ThreadRng::new()? #404

Closed

Description

@vks

This would be more consistent with OsRng, EntropyRng, JitterRng, ReseedingRng and BlockRng.

Activity

  1. dhardy commented on Apr 17, 2018

    @dhardy
    Member

    I do not support this. Calling thread_rng has low overhead (just creating another reference) and could be optimised to just a check and pointer copy. The ThreadRng type is just a handle to another object; unfortunately this is not obvious from the name so ThreadRng::new sounds like it is doing a lot more work than merely creating a handle.

    OsRng is also just a handle really and I did think about replacing its new with e.g. os_rng, but didn't see much point.

  2. vks commented on Apr 17, 2018

    @vks
    ContributorAuthor

    I don't share that sentiment, new() is just the constructor-by-convention. It is often very lightweight, though not necessarily so. To me it seems like the constructor for ThreadRng (thread_rng) has a non-idiomatic name.

    ThreadRng::new sounds like it is doing a lot more work than merely creating a handle.

    It is doing a lot of work if it is the first call in the thread.

    OsRng is also just a handle really

    That is my point, right now we are inconsistent.

  3. pitdicker commented on Apr 17, 2018

    @pitdicker
    Contributor

    I wouldn't remove thread_rng(), it is used too much. But adding ThreadRng::new() seems harmless to me.

  4. dhardy commented on Apr 17, 2018

    @dhardy
    Member

    Having both will just lead to pointless style wars.

  5. dhardy commented on May 3, 2018

    @dhardy
    Member

    I agree that we shouldn't simply have thread_rng() -> impl Rng because this prevents users from embedding the type in structs, (which may be useful even though it isn't common usage); hence ThreadRng::new() does make intuitive sense, so this may be a good option.

    See also this point about replacing ThreadRng with perhaps two alternatives: StrongRng and WeakRng.

    In any case, I think we should postpone these ideas until after the 0.5 release.

  6. dhardy commented on Jun 15, 2018

    @dhardy
    Member

    Since there do appear to be quite a few people who watch this repository and this is mostly style, can I get some more opinions on this, i.e. do you prefer writing thread_rng() or ThreadRng::new()? We could also have both, but it is redundant.

    Either way, we already have the ThreadRng type (fn thread_rng() -> ThreadRng).

  7. dhardy commented on Aug 1, 2018

    @dhardy
    Member

    There is almost no interest on this, so I guess we can just forget it.

  8. added this to the 0.6 release milestone on Aug 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    E-questionParticipation: opinions wanted

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions