ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:101124] [Ruby master Feature#17351] Deprecate Random::DEFAULT
@ 2020-11-27 11:16 eregontp
  2020-11-27 14:54 ` [ruby-core:101130] " ko1
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: eregontp @ 2020-11-27 11:16 UTC (permalink / raw
  To: ruby-core

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

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

* Author: Eregon (Benoit Daloze)
* Status: Open
* 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/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [ruby-core:101130] [Ruby master Feature#17351] Deprecate Random::DEFAULT
  2020-11-27 11:16 [ruby-core:101124] [Ruby master Feature#17351] Deprecate Random::DEFAULT eregontp
@ 2020-11-27 14:54 ` ko1
  2020-11-27 14:56 ` [ruby-core:101131] " ko1
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: ko1 @ 2020-11-27 14:54 UTC (permalink / raw
  To: ruby-core

Issue #17351 has been updated by ko1 (Koichi Sasada).


> 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.

As mentioned here: https://bugs.ruby-lang.org/issues/17322#note-7
there are several users.

For example, I will use `Random::DEFAULT` for the default random generator for dice rolling method like:

```ruby
def roll rnd = Random::DEFAULT
  rnd.rand(6)+1
end
```

for hobby use (non-serious use case).

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

* Author: Eregon (Benoit Daloze)
* Status: Open
* 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/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [ruby-core:101131] [Ruby master Feature#17351] Deprecate Random::DEFAULT
  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 ` ko1
  2020-11-27 15:05 ` [ruby-core:101132] " eregontp
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: ko1 @ 2020-11-27 14:56 UTC (permalink / raw
  To: ruby-core

Issue #17351 has been updated by ko1 (Koichi Sasada).


I don't against to remove `Random::DEFAULT`, but need to care about current users.

```ruby
def roll rnd = nil
  (rnd ? rnd.rand(6) : rand(6)) + 1
end
```

is one way, but I think some people can like previous definition.

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

* Author: Eregon (Benoit Daloze)
* Status: Open
* 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/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [ruby-core:101132] [Ruby master Feature#17351] Deprecate Random::DEFAULT
  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 ` eregontp
  2020-12-10  7:04 ` [ruby-core:101362] " matz
  2021-10-27 11:02 ` [ruby-core:105821] " Eregon (Benoit Daloze)
  4 siblings, 0 replies; 6+ messages in thread
From: eregontp @ 2020-11-27 15:05 UTC (permalink / raw
  To: ruby-core

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


It seems pretty rare to need to supply a custom Random instance.
But in such a case, it would be easy to create an explicit one in e.g. the constructor:
```ruby
class Dice
  def initialize(random = Random.new)
    @random = random
  end

  def roll
    @random.rand(6) + 1
  end
end
```

If it needs to scale and run well with parallel threads, the built-in `Kernel#rand` is probably the only good option.

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

* Author: Eregon (Benoit Daloze)
* Status: Open
* 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/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [ruby-core:101362] [Ruby master Feature#17351] Deprecate Random::DEFAULT
  2020-11-27 11:16 [ruby-core:101124] [Ruby master Feature#17351] Deprecate Random::DEFAULT eregontp
                   ` (2 preceding siblings ...)
  2020-11-27 15:05 ` [ruby-core:101132] " eregontp
@ 2020-12-10  7:04 ` matz
  2021-10-27 11:02 ` [ruby-core:105821] " Eregon (Benoit Daloze)
  4 siblings, 0 replies; 6+ messages in thread
From: matz @ 2020-12-10  7:04 UTC (permalink / raw
  To: ruby-core

Issue #17351 has been updated by matz (Yukihiro Matsumoto).


OK, accepted.

Matz.


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

* Author: Eregon (Benoit Daloze)
* Status: Open
* 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/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [ruby-core:105821] [Ruby master Feature#17351] Deprecate Random::DEFAULT
  2020-11-27 11:16 [ruby-core:101124] [Ruby master Feature#17351] Deprecate Random::DEFAULT eregontp
                   ` (3 preceding siblings ...)
  2020-12-10  7:04 ` [ruby-core:101362] " matz
@ 2021-10-27 11:02 ` Eregon (Benoit Daloze)
  4 siblings, 0 replies; 6+ messages in thread
From: Eregon (Benoit Daloze) @ 2021-10-27 11:02 UTC (permalink / raw
  To: ruby-core

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/

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-10-27 11:02 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [ruby-core:105821] " Eregon (Benoit Daloze)

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).