Uh oh!
There was an error while loading. Please reload this page.
Remove the [] notation for taking a whole slice. - #491
Conversation
sinistersnare
commented
Nov 29, 2014
+1, |
ftxqxd
commented
Nov 29, 2014
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 |
reem
commented
Nov 30, 2014
I've been doing much the same thing as @P1start, I find |
blaenk
commented
Nov 30, 2014
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! |
Valloric
commented
Dec 1, 2014
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. |
liigo
commented
Dec 1, 2014
+1, please hold it off currently |
reem
commented
Dec 1, 2014
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. |
mcpherrinm
commented
Dec 2, 2014
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 |
Ericson2314
commented
Dec 2, 2014
Big +1, for the reasons already stated. |
glaebhoerl
commented
Dec 2, 2014
I agree with @mcpherrinm: we should keep it as
This is cute; I hadn't thought of it this way. :) |
mitsuhiko
commented
Dec 2, 2014
|
thestinger
commented
Dec 2, 2014
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. |
thestinger
commented
Dec 2, 2014
@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. |
thestinger
commented
Dec 2, 2014
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. |
thestinger
commented
Dec 2, 2014
AFAIK, the proposal add a magical borrowing operator was rejected. It would make |
arthurprs
commented
Dec 2, 2014
[ ] is consistent(ish) with slicing syntax and it's less noisy, I vote to keep it. |
thestinger
commented
Dec 2, 2014
@mcpherrinm: I wouldn't mind having |
thestinger
commented
Dec 2, 2014
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 |
cl91
commented
Dec 2, 2014
@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]. |
thestinger
commented
Dec 2, 2014
I think it's important to keep in mind that the |
arthurprs
commented
Dec 2, 2014
@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). |
thestinger
commented
Dec 2, 2014
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. |
thestinger
commented
Dec 2, 2014
Note that adding this syntax could happen at any point in the future, but deciding between |
thestinger
commented
Dec 2, 2014
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... |
blaenk
commented
Dec 2, 2014
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 |
arthurprs
commented
Dec 2, 2014
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. |
thestinger
commented
Dec 2, 2014
The ability for someone to provide two different implementations despite all the standard cases being the same makes it that much more confusing. |
Earnestly
commented
Dec 2, 2014
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! |
mcpherrinm
commented
Dec 2, 2014
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. |
SiegeLord
commented
Dec 3, 2014
While |
thestinger
commented
Dec 3, 2014
@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 |
bstrie
commented
Dec 3, 2014
+1 to removing |
lilyball
commented
Dec 3, 2014
+1 to removing I am slightly concerned that removing |
thestinger
commented
Dec 3, 2014
I'm strongly against #241. Having |
thestinger
commented
Dec 3, 2014
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? |
Gankra
commented
Dec 3, 2014
@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) |
ftxqxd
commented
Dec 4, 2014
@thestinger#241 doesn’t propose making |
arthurprs
commented
Dec 4, 2014
@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. |
aturon
commented
Dec 4, 2014
Just a heads-up: that's not what RFC 241 proposes. The RFC you're talking about was closed a while ago. |
liigo
commented
Dec 4, 2014
I don't think we should replace an ugly |
nrc
commented
Dec 4, 2014
@liigo we're not talking about replacing - |
pythonesque
commented
Dec 4, 2014
+1 to this RFC, kill [] with fire. When you want as_slice(), write as_slice(). |
nrc
commented
Dec 6, 2014
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