-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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: '..' as alternative syntax for slicing #64118
Comments
You can already do what you want without a new operator?
That's the same as
That's the same as
That's the same as |
@randall77 - But overwhelming association of short term declaration := in the file while search slicing and short term declaration is pretty rough as already horizontal ellipses ... gives meaning variable params and in array as well where .. is closer to that and feels like in the spectrum of operators. |
I don't think we want to change the language, which is a very big deal, just to make text search for slicing easier. |
Please fill out https://github.com/golang/proposal/blob/master/go2-language-changes.md when proposing language changes |
I will do @seankhliao |
@seankhliao The template has questions, how to make answer them and respond. Fork and PR? |
copy and answer them here |
Would you consider yourself a novice, intermediate, or experienced Go programmer? What other languages do you have experience with? Would this change make Go easier or harder to learn, and why? Has this idea, or one like it, been proposed before? What is the proposed change? Please describe as precisely as possible the change to the language. Adding a .. operator for slicing will improve Golang over all in terms of slice. If you want to search where slice is used in the language it will be easier. As this operator will be dedicated to that operation where as : is used in pretty much other places as mentioned above. What would change in the language spec? Please also describe the change informally, as in a class teaching Go. Is this change backward compatible? Breaking the Go 1 compatibility guarantee is a large cost and requires a large benefit. What is the cost of this proposal? (Every language change has a cost). How many tools (such as vet, gopls, gofmt, goimports, etc.) would be affected? What is the compile time cost? What is the run time cost? Can you describe a possible implementation? Do you have a prototype? (This is not required.) How would the language spec change? Orthogonality: how does this change interact or overlap with existing features? Is the goal of this change a performance improvement? If so, what quantifiable improvement should we expect? How would we measure it? Does this affect error handling? If so, how does this differ from previous error handling proposals? Note : Please let me know If I missing something |
This proposal introduces an entirely new token that is functionally indistinguishable from the colon. That alone makes it hard to justify, and I don't support it as it creates duplication (and therefore confusion) for extremely minimal benefit. It's not like it's hard to search for But if this proposal were to move forward I'd prefer to use the existing token |
Given that this is just an alternative syntax for an existing feature, this is a likely decline. Leaving open for a further four weeks for final discussion. |
No change in consensus, so declined. |
Proposal :
Slicing is one of the important operation in Golang while dealing with slices or arrays. Currently colon operator is used :
It looks like this
if you search across a go file or func most of local variables are driven through short term variable declaration :=, you may be even able to notice that above. However if you see slicing as an operation, it is basically getting a part from the underlying array either getting it with above index or getting then all it is better denoted by range operators like in shell (..)
as currently vardiac symbols are used for Passing arguments to ... parameters If f is [variadic](https://go.dev/ref/spec#Function_types) with a final parameter p of type ...T, then within f the type of p is equivalent to type []T
If the final argument is assignable to a slice type []T and is followed by ..., it is passed unchanged as the value for a ...T parameter. In this case no new slice is created.
or The notation ... specifies an array length equal to the maximum element index plus one.
So i am proposing 2 dots or .. as a notion for slicing operation with or without index and I can show some examples below
How the change looks like
Current
Proposed
Example
Proposed
Example
The text was updated successfully, but these errors were encountered: