ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: "Eregon (Benoit Daloze)" <noreply@ruby-lang.org>
To: ruby-core@ruby-lang.org
Subject: [ruby-core:105821] [Ruby master Feature#17351] Deprecate Random::DEFAULT
Date: Wed, 27 Oct 2021 11:02:25 +0000 (UTC)	[thread overview]
Message-ID: <redmine.journal-94346.20211027110224.772@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-17351.20201127111644.772@ruby-lang.org

Issue #17351 has been updated by Eregon (Benoit Daloze).


Just realized, another way to write that roll method (without deprecation) is:
```ruby
def roll rnd = Random
  rnd.rand(6)+1
end
```

I also noticed deprecated constants are no longer warned by default as they depend on `Warning[:deprecated]`.

----------------------------------------
Feature #17351: Deprecate Random::DEFAULT
https://bugs.ruby-lang.org/issues/17351#change-94346

* Author: Eregon (Benoit Daloze)
* Status: Closed
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
----------------------------------------
From https://bugs.ruby-lang.org/issues/17322#note-11

I think we should deprecate the `Random::DEFAULT` constant, it doesn't make sense anymore and it's longer than using Random class methods (Random.rand) or Kernel instance methods (#rand).
Also, people might expect it to be global.

If users want a Random instance they should just use `Random.new`, not assume there is a global instance in Random::DEFAULT, which is actually rather misleading now (Random::DEFAULT is no longer an instance of Random).

Also note that JRuby & TruffleRuby use a per-thread instance for Kernel#rand, etc, to avoid contention (otherwise it becomes a huge source of contention when threads run in parallel).
Which means on those implementations using Random::DEFAULT was inefficient (extra synchronization).

So for all these reasons I think it's time to deprecate `Random::DEFAULT` and then later remove it (in 3.1?).

I don't think there is any use case for `Random::DEFAULT`, but happy to hear if there is and there is no trivial replacement.



-- 
https://bugs.ruby-lang.org/

      parent reply	other threads:[~2021-10-27 11:02 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-27 11:16 [ruby-core:101124] [Ruby master Feature#17351] Deprecate Random::DEFAULT eregontp
2020-11-27 14:54 ` [ruby-core:101130] " ko1
2020-11-27 14:56 ` [ruby-core:101131] " ko1
2020-11-27 15:05 ` [ruby-core:101132] " eregontp
2020-12-10  7:04 ` [ruby-core:101362] " matz
2021-10-27 11:02 ` Eregon (Benoit Daloze) [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=redmine.journal-94346.20211027110224.772@ruby-lang.org \
    --to=ruby-core@ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).