Thanks for writing this up!
I'm a little bias, so hopefully none of my arguments show that
In general, I'm not a fan of the rename. I actually disagree regarding that fact that the default generator will be rarely explicitly used. I think with the introduction of this new API that many more people will be exploring and experimenting with ways to incorporate this into their own APIs. I'm actually writing up another proposal to further increase functionality in RandomNumberGenerator
which would require that some users have to interact with the generator itself, rather than a method take a generator. I don't want to go too off topic here, but I imagine many others will write extensions onto RandomNumberGenerator
to further increase functionality to fit their needs. Example:
let buffer = ...
Random.default.fillBuffer(buffer)
// vs
DefaultRandomNumberGenerator.shared.fillBuffer(buffer)
I think operations like these prove to show that there is an unnecessary verbosity in what it's performing.
I agree with this line of thinking in that a singleton called shared
is generally attached to reference semantic types (which this does not have). I think the only great spelling for this is actually default
, but this would look something like DefaultRandomNumberGenerator.default
.
Now, I will agree that Random
on its own is ambiguous, but I did this for a reason. In the future if Swift is to ever add a deterministic RNG in the stdlib, it could be shipped under something like Random.xorshift128Plus
as a globally initialized instance of Random.Xorshift128Plus
(seeded from Random.default
of course, along with having the ability to initialize your own instance of this type of course). Now this is thinking really far into the future, but this flexibility with Random
allows us to do some really cool things if Swift ever reaches a point where it needs it (such as adding new generators with obvious names that would break a lot of code if not namespaced under Random
).
I don't entirely agree with the argument that this has precedence in the stdlib. The only type in the stdlib with the prefix Default
is DefaultIndicies
(at least from my findings) and that type doesn't conform to some magic protocol called Indicies
.
Overall, I don't really see a huge advantage using DefaultRandomNumberGenerator.shared
over Random.default
rather than being overly clear about what it is. I think many people will want to use this new API that they will eventually come across DefaultRandomNumberGenerator.shared
and feel a little intimidated to continue using it.
I apologize if anything I said was a little biased!