-
Notifications
You must be signed in to change notification settings - Fork 17.6k
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: Go 2: make final index in a three-index slice expression default to the middle index value #25638
Comments
I agree that |
Currently in a simple slice expression, with two values, if you omit the first index it is replaced by the lowest possible value ( Erring on the side of caution, proposal rejected. Thanks for the suggestion, though. |
Just noticed this was declined. Some final arguments. Although the absence third index default to In fact, I think the rationale of thinking the absence third index default to
I think one reason people don't see it often is it is some verbose to written, which is why this proposal was made, :). I can't say this is main reason three-index forms is seldom used, but it really counts for some percentage, about 15%, maybe. And BTW, this proposal is Go 1 compatible. |
The current three-index slice form index presentation rule quite discourages gophers to use three-index slice forms. The current rule requires the middle and final index must be both represent in a three-index slice form, which makes three-index slice form quite verbose.
For example, many library may contain functions like the following one:
The defect (if it is not a bug) of the function
NewX
is it may modify the underlying data of passed arguments. It is better to useappend(opts[:len(opts):len(opts)], hiddenOpts...)
instead. But for its verbosity, its uses are limited.In fact, in practice, when a three-index form is used, the final index is often same as the middle index. In particular,
s[ : len(s) : len(s)]
is used most often. So I propose the following simplified three-index slice forms:So that, we can use
append(opts[::], hiddenOpts...)
in the aboveNewX
function, without too verbose.The text was updated successfully, but these errors were encountered: