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

proposal: make() multi-dimensional slices more succinctly #24879

Closed
andres-valdes opened this issue Apr 16, 2018 · 4 comments
Closed

proposal: make() multi-dimensional slices more succinctly #24879

andres-valdes opened this issue Apr 16, 2018 · 4 comments

Comments

@andres-valdes
Copy link

andres-valdes commented Apr 16, 2018

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

go version go1.10.1 darwin/amd64

Does this issue reproduce with the latest release?

Yes.

What did you do?

Frequently declare 2D slices (slices of slices).

Whenever I do, it feels less straightforward than it should, which I feel goes against Go's commitment to simplicity.

What did you expect to see?

sliceOfSlices := make([][]Type, x, y)

What did you see instead?

sliceOfSlices := make([][]Type, x)
for i := range sliceOfSlices {
    sliceOfSlices[i] = make([]Type, y)
}
@gopherbot gopherbot added this to the Proposal milestone Apr 16, 2018
@cznic
Copy link
Contributor

cznic commented Apr 16, 2018

sliceOfSlices := make([][]Type, x, y)

Note that the above is valid today, but has different semantics: https://play.golang.org/p/XUt9Lf0k8Cn

@andres-valdes
Copy link
Author

andres-valdes commented Apr 16, 2018

Note that the above is valid today, but has different semantics: https://play.golang.org/p/XUt9Lf0k8Cn

I've noticed that this is valid, but it seems to denote the cap:
https://play.golang.org/p/NTu9P1zhS52

Perhaps instead it could be:

sliceOfSlices := make([][]Type, len(sliceOfSlices), len(sliceOfSlices[i]), cap(sliceOfSlices), cap(sliceOfSlices[i]))

It just seems more powerful and intuitive.

@agnivade
Copy link
Contributor

@AnvilDev - This was already proposed in #6282 and declined. You can go through that thread to understand the reasoning behind that decision.

@mvdan
Copy link
Member

mvdan commented Apr 16, 2018

Yes, this has been discussed before. It doesn't seem like this proposal adds anything new, so I'm going to close it as a duplicate.

@mvdan mvdan closed this as completed Apr 16, 2018
@golang golang locked and limited conversation to collaborators Apr 16, 2019
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

5 participants