-
Notifications
You must be signed in to change notification settings - Fork 1.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
Remove the []
notation for taking a whole slice.
#491
Conversation
+1, |
I agree with this RFC—for slicing, ‘there should be one obvious way to do it’. I’ve switched from writing Another advantage of this RFC is that we can remove slicing on strings. Being able to quickly convert a |
I've been doing much the same thing as @P1start, I find |
Yesss please. The As I've said before, I also agree that in the worst case, So I completely agree with this. Good one @nick29581! |
At the 1.0 gate, the number of people who are "just starting" will greatly outnumber the people who understand the system. The barrier to entry must be low. |
+1, please hold it off currently |
I guess the best thing to do would be to get deref coercions pre-1.0, but since it's backwards compatible, that seems unlikely to happen. |
If we allow Really I just want to support everything python slice notation does. (even if the : has fallen over sideways), which would additionally include support for negative indexing |
Big +1, for the reasons already stated. |
I agree with @mcpherrinm: we should keep it as
This is cute; I hadn't thought of it this way. :) |
|
It's not confusing to anyone with even a basic grasp of the language, and I think it's perfectly readable. I don't think delaying the need to learn the basics by hiding it behind magical sugar is going to help newcomers. There is a reason that people find very basic languages without lots of magic like Go to be easy to pick up and use. |
@nick29581: I strongly support your proposal. I think removing duplicate features / unnecessary magic is a very important part of making a usable language. Using consistent and explicit syntax is often better than having specialized sugar for many cases. This syntax is already widely used and relies on the fundamental core of the language so I don't buy the claims that is confusing at all. |
Sugar increases the barrier to entry. It makes the language harder to grasp by adding special cases. Every Rust user needs to understand the basics of borrowing and dereferencing, and adding special sugar for this case just adds one more thing they need to keep in their head. Arguing for additional complexity / syntax is not helping newcomers. |
AFAIK, the proposal add a magical borrowing operator was rejected. It would make |
[ ] is consistent(ish) with slicing syntax and it's less noisy, I vote to keep it. |
@mcpherrinm: I wouldn't mind having |
This is a coherent, simple system:
Having an additional way to do it for slices is not making the language simpler or easier to learn. Users will encounter the pattern in many other places, and they will also encounter code doing it the other way for slices because it's so obvious. I don't buy that a larger grammar makes the code easier to learn. Both |
@mitsuhiko @arthurprs The problem is that if you have a vector of strings, you will have to write v[1][] to get a slice, which makes v look like a multidimensional array. In this case &_v[1] will look better (or even better &v[1]). There was a discussion on reddit about how to get the cmd arguments where they have to do os.args[1][], which is arguably less good looking than &os.args[1] or &_os.args[1]. |
I think it's important to keep in mind that the |
@thestinger I understand your reasoning but we should still have a syntax for full slice (even if deref-and-borrow results in the same thing). |
Why should we have another way of doing the same thing? I'm not hearing any reasons that don't amount to the claim that extra magic / complexity / inconsistent syntax makes life easier for newcomers. |
Note that adding this syntax could happen at any point in the future, but deciding between |
Oh, and not only does it imply duplicate syntax but also a duplicate method. It's very weird to have two separate traits / methods for these types to implement that are identical and overload a different thing... |
Yeah, to repeat, I'm strongly in favor of removing it, and in the absolute I'm not sure on the status of &String coercions but we should also |
I can't think of any examples that would make sense to have different implementations for borrow and full-slice but that doesn't mean they don't exist. |
The ability for someone to provide two different implementations despite all the standard cases being the same makes it that much more confusing. |
All this sugar does is make it harder for newcomers to really understand the language, at least from my experience as a newcomer to many languages. Sugar will always eventually become a pitfall when the same logic suddenly doesn't apply in a certain context. I personally this very frustrating as it now requires constantly having to remember the differences and how they do or don't work in some places. If you're not bound by having to support legacy systems, please consider very carefully when adding sugar in general! |
My argument about consistency doesn't really hold with the way the In that case ++ to removing [] and special handling of that case. If we support [..], it should not be because we explicitly handle it, but because it falls out of a design to do so. |
While |
@SiegeLord: The ability to overload by-value dereference would cover the same use case, so I don't see why that matters. I think it was a bit questionable to implement dereferencing for |
+1 to removing |
+1 to removing I am slightly concerned that removing |
I'm strongly against #241. Having |
Attempting to paper over the inherent complexity in the memory model with magical sugar does not make the language simpler. It makes the language more complex by adding lots of special cases with non-obvious workarounds. Rust has already tried going down that path, and it never turns out well. Why are special cases like that even still on the table? |
@thestinger With respect, few people are as familiar with the language's storied history as you are. Further, it is not uncommon to find decisions in the compiler or standard libraries that made sense at the time, but are now dubious in the context of current conventions and design. Rust is very-much-so a moving target. With that in mind, it doesn't seem unreasonable to revisit previously discussed design issues every now and then. Or at very least, it would be more helpful to direct interested parties to the previous discussions so that they can benefit from everyone's past experiences. This would likely be more productive than simply dismissing such discussion as "already tried". (I do not have a particularly strong opinion on the specific issue at hand, I just think that revisiting/scrutinizing past decisions is important) |
@thestinger #241 doesn’t propose making |
@SiegeLord wrote it better than I could. I'm all in favor of zen of python but in my opinion we should preserve [ ] as it may not be equivalent to borrow in all cases. |
Just a heads-up: that's not what RFC 241 proposes. The RFC you're talking about was closed a while ago. |
I don't think we should replace an ugly |
@liigo we're not talking about replacing - |
+1 to this RFC, kill [] with fire. When you want as_slice(), write as_slice(). |
We (the Rust team) discussed this in some depth today. The arguments for and against were pretty much as already outlined in the RFC. We are pretty much agreed that we will not see any form of cross-borrowing coercion in Rust for 1.0, therefore, with this RFC, we would be living with the Importantly, we clarified that under RFC #439, the syntax for creating a slice is On the issue of |
cc @aturon
rendered