Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

all: duplicate functions should be removed from the standard library #48826

Closed
ghost opened this issue Oct 6, 2021 · 1 comment
Closed

all: duplicate functions should be removed from the standard library #48826

ghost opened this issue Oct 6, 2021 · 1 comment

Comments

@ghost
Copy link

ghost commented Oct 6, 2021

Hello,

So I've been coding in Golang for a while and there are a few bugs here and there, but one of the issues I have with the standard library is that there are two random packages, which doesn't make sense because all the functions from one package overlap with the functions from the other, so I was wondering if we could have a single package that can do everything.

There will be less code for Golang maintainers to maintain, and it will be easier for new Golang users to figure out what to use, We may progressively remove the crypto/rand package and just use the math/rand package after that.

I'm not just talking about one package; I've seen so many identical functions that accomplish the exact same thing that it's ridiculous.

@ghost ghost changed the title Remove crypto/rand package. Duplicate functions should be removed from the standard library. Oct 6, 2021
@mknyszek mknyszek changed the title Duplicate functions should be removed from the standard library. all: duplicate functions should be removed from the standard library Oct 6, 2021
@mknyszek mknyszek added this to the Backlog milestone Oct 6, 2021
@mknyszek
Copy link
Contributor

mknyszek commented Oct 6, 2021

The duplication is there for a reason, as a general rule. crypto/rand and math/rand in particular expose the same API, but target different audiences. math/rand provides a pseudo-random number generator that is relatively fast, and suitable for a wide range of applications (random number generators in tests, for games, for rate limiting, etc.). However that generator is not cryptographically secure, meaning that given some range of attack vectors, it's possible to write an algorithm that figures out what future values will be. Because cryptography applications rely on the random number being hard to predict, that makes math/rand a bad choice. Hence the existence of crypto/rand, which provides these guarantees.

Closing this issue unless you have other specific examples. Please be aware that the Go project cannot remove any functions from standard library packages in order to maintain the Go 1 backwards compatibility guarantee. There may be situations in which some functions can be written in terms of others (and this does happen, see some recent io/ioutil functions being rewritten in terms of their non-deprecated os and io counterparts), so that would be the way forward in any of these situations. Please feel free to contribute any such deduplications directly, no need to file an issue. See https://golang.org/doc/contribute.

Again, do note that some actual duplication exists for a reason. There is one example that pops into my head, but that one, at the moment, is unavoidable (specifically, math/bits and runtime/internal/sys have some duplicate code).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants