palimondo
(Pavol Vaskovic)
May 25, 2018, 7:31am
43
For the benefit of people that weigh-in on this amendment review, but didn’t have time to participate in previous discussions, let’s...
Recap:
Suggestion for DefaultRandomNumberGenerator
first appears on SE-0202 proposal review :
No reason given.
Second mention down-thread:
No reason given.
Third mention further down-thread:
You could also implement Random.default
as a computed property that always vends a fresh generator (since all such values are equivalent):
extension Random {
var `default`: DefaultRandomNumberGenerator {
get { return DefaultRandomNumberGenerator() }
set { /*discard*/ }
}
}
This is in a context of discussing the implementation details with regards to thread-safety. @Joe_Groff was replying with possible workaround to specific memory exclusivity concerns raised by @nnnnnnnn .
Fourth time down-thread was after the proposal acceptance decision:
Was there consideration of the Random
and Random.default
naming? It seems like a sub-par name for the standard library random number generator. I proposed DefaultRandomNumberGenerator
and it appeared to get consensus acceptance (e.g. here ). I don’t mind if the core team decided against an alternative naming, just checking this detail wasn’t overlooked.
The consesus acceptance claim is quite the misrepresentation , given the context I provided above.
Moving on to the amendment pitch phase :
I am recommending an amendment to the proposal which provides a better name for this stdlib type. I propose that the stdlib generator should be called DefaultRandomNumberGenerator
. This name makes it plain that it is a default implementation of the RandomNumberGenerator
protocol. Random
is far too generic and does not allude to the fact that other sources of randomness can (and should) exist. The name DefaultRandomNumberGenerator
also indicates that it is merely the system default, and developers should consider whether other generators would be more appropriate for their particular case.
Reason given for renaming: promotion of other than default implementations . (?) That’s non sequitur .
The author of SE-0202, @Alejandro , clarifies the original vision in his reply:
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…
Followed by the amendment proposal author:
The idea that Random
can act as a namespace is neat, but this intent is not described in the original proposal at all. If namespacing these types is worthwhile, then even so I would vote for some syntactic amendments. Random
should be a enum (or a formal namespace declaration when we have one) and offer a static method like default
which vends a DefaultRandomNumberGenerator
. It doesn’t really make sense to have a Random
struct type also be the namespace.
@Alejandro follows up by detailed explanation for the current SE-0202 design based on performance considerations and supports the original naming with thorough term-of-art justification from other languages:
I said could
The current design states that Random is the default generator, rather than some empty namespace. Ben is suggesting that this name is:
There is a term-of-art justification for this name as well. In many languages, such as Java, Scala, Kotlin, D, C# (.NET), Ruby, this spelling is consistently used as the stdlib RNG. Now I understand Swift isn't one of these other languages, but I think it's important to evaluate what other languages have done. Granted these languages get m…
It is noted that even though Swift’s in-the-wild practice is to use empty enum
s as de-facto namespaces (due to them currently missing from the language), it’s just a convention and technically struct
s can play this role as well.
I’m not suggesting the current name is ‘actively harmful’, but given the proposal isn’t implemented yet in public Swift I think there is a much lower bar needed to critique it and change it to something better. DefaultRandomNumberGenerator.shared
is better, and I believe we should roll with that.
I brought up the same opinion in the review phase and it seemed to gain some community acceptance; an administrative error has led to this amendment thread being necessary as explained at the bottom of the original post.
The definition of Bikeshedding ?
There seemed to be mild consensus forming on the topic of splitting the default implementation struct
and namespace enum
. This is not the subject of this amendment proposal.
1 Like