-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Champion "slicing" / Range (16.3, Core 3) #185
Comments
Do we still need this feature while we have We could just create readonly ref collection couldn't we? struct ReadonlyRefCollection<T>
{
T[] array;
int slice,length;
public ref T this[int i] { get => ref array[i] }
} |
@Thaina Slicing may end up being just that, though it is possible we will want a special syntax for taking a slice, like |
@gafter Thanks for answer but then I would disagree for adding syntax just for that Extension method |
Would the runtime be smart enough to know it can collect/free parts of eg. an underlying array that is not in a slice? In other words, if I have
I assume there are huge complications with object headers that would make this very complicated. But it sure would be nice. |
@chrisaut The way I read it is a slice is a view over an existing array so I think that |
@Thaina str[a:b] reads a lot nicer than str.Slice(a, b) but if you don't like that you could use the API directly. :) |
@eyalsk Sorry to say that I think completely opposite. It not intuitive at all to assume that On the contrary we had |
@chrisaut I think it would be too hard to determined if resizing array, which involve copy and clearing memory, would yield performance when it really necessary. Too many scenario compiler need to do guesswork such as, what if the sliced array will also dispose in the next minute? Then it no point to waste time dispose the old one anyway Developer could just explicitly optimized by manually resize |
In case special syntax is needed, I suggest to use the range operator from Pascal, which is The |
@eyalsk @Thaina I'm not talking about making copies, slices should absolutely under no circumstance require copying of data, that's their entire point. I'm talking about making the runtime smart enough to understand, that a given array only has ranges x-y reachable. An array is basically a bunch of header info, followed by a block of memory. If the GC understood that for arrays (and maybe other types later), before reclaiming it has to check some state somewhere to see if any slices are holing onto it, it could understand that only a small region is "alive" and free the rest. This is just a rough idea. |
@chrisaut Slice itself never need to copy, unless it trying to do what you want, resize it To have the mechanism you said, partially return memory to the pool, involve CLR optimization. Not about language or compiler |
@chrisaut Where did I say that slices are about making copies? please reread what I wrote. |
There's always first time... We didn't have many things in C# and now we have them so it isn't really an argument, if you don't find the syntax pleasant to read then that's a different story. :) |
I am also wondering what happens when the Version 0 int[] primes = new int[] { 2, 3, 5, 7, 9, 11, 13 };
int[:] a = primes[5:2]; // throws an exception
int[:] b = primes[1:0]; // throws an exception
int[:] c = primes[0:-1]; // throws an exception Version 1 int[] primes = new int[] { 2, 3, 5, 7, 9, 11, 13 };
int[:] a = primes[5:-3]; // A slice with elements {11, 9, 7}
int[:] b = primes[1:-2]; // A slice with elements {3, 2}
int[:] c = primes[0:-1]; // A slice that yields {2} and then throws an exception Version 2 int[] primes = new int[] { 2, 3, 5, 7, 9, 11, 13 };
int[:] a = primes[5:2]; // A slice with elements {11, 9, 7}
int[:] b = primes[1:0]; // A slice with elements {3, 2}
int[:] c = primes[0:-1]; // A slice that yields {2} and then throws an exception |
@eyalsk Well, that's why most of the time I would like to recycle keyword more than add new And as I said, it's not that we can't. I just argue that it not intuitive because we never have it. Compare to what we already have, a |
@chrisaut Just to make it crystal clear, what I meant is that if you no longer need a reference to the array but you still want to have the slice around then I think that you will need to make a copy of the slice, just a hunch based on my understanding, I could be wrong. |
@eyalsk I understand what you said to mean that for what I want, slices would need to copy. I don't think it does. Apologies if that's not what you want. @Thaina yes of course it would require clr/gc work, but many new features would require that. I'd guess slices in general will need runtime support (regarless of the partial freeing) as slices are not just a new Type. |
@Thaina async/await is intuitive? pattern matching is intuitive? |
@eyalsk Well, intuitive relative to what? I was talking Actually I would argue that many feature of pattern matching is also really not intuitive. I was propose alternative many times but I am not contributor so my voice is not important But still many feature of pattern matching are intuitive. such as But the point is many feature in pattern matching have nothing to comparing to. So add new one is not necessary to be intuitive But async/await is good example. It is really more intuitive to write code than callback. You can write a loop intuitively just add await I would also argue that we should not need await and should only have async keyword in But as I said, intuitive is relative. async/await still more intuitive than callback. But |
Just to cite the relevant part from the proposal:
Therefor, I wouldn't expect any clever tricks here but I could be wrong. :) |
@eyalsk I think what @chrisaut means is. If we have alloc memory for array, suppose from ptr0 to ptr50 Then we slice it at ptr20 to ptr30 and then stop using the original array CLR could dealloc ptr0 to ptr18 and ptr31 to ptr50. And maybe the implementation of slicing array could force CRL to check that But I don't think CLR can do thing like this |
Intuitive relative to the person, many language constructs require some learning so this wouldn't be any different, especially when the person has no prior knowledge.
Thaina being a Contributor doesn't mean "anything" and your voice is as important as mine.
It's straightforward to create asynchronous methods but it isn't straightforward to understand how asynchronous code works and what it means, especially for people that never did such work before. My point being is that there's a bit of learning to do before you can use a feature and not so much about how it can be more intuitive... |
Existing methods in the BCL that have similar behavior (such as |
Not at all. Relative is objectively compare with existing things. Even leaning curve is also relative to what exist and what newly introduced
Disagree. people who not being contributor might be important but I never see it will be the same importance as contributor
Still the same word, relative. If there are newbie learning C# there are callback function and async/await we can present to let them learn how to do asynchronous. async/await has less learning curve compare to callback function that not straightforward My point is comparing learning curve with similar feature is necessary. And I would vote that we should better use |
And a person isn't a thing?
Thaina... let's not get into the meaning of a Contributor when it's pretty well defined and has absolutely nothing with the subject.
Thaina you would still have the ability to use the API directly. I understand that you don't like the syntax but what do you think about the syntax that was proposed by @MovGP0? personally I find the proposed syntax |
i am totally happy with the foreach(var item in 3..5){ /* 3,4,5 */ }
foreach(var item in a[3..5]){ /* a[3], a[4], a[5] */ } |
As always you are the one who pick the word to argue with me. So you stop yourself not telling me to stop what I don't start
If that's your argument then you would never ever come mess with my threads in the past. Remember when you annoyingly mock me when I try to introduce To introduce new syntax have many cost and drawback or else we would have all syntax we could imagine already. Same here that you like this syntax so you want it and I'm against it because it make code more weird and cost too much for little benefit I know why you try to argue with me in the past even you make fun of me in every aspect and make our argument become silly. You should understand yourself too |
The current proposal already supports
I'd find it wildly unconvincing if anyone claims that the obscure sequence of symbols Surprisingly multiple people already turned this ordinal topic into a heated religious-style debate, which suggests that more time and more research is needed to clarify the situation. I do completely understand that it's frustrating to delay it to C# 8.1, but even more frustrating would be if a mistake is set in concrete forever in C# 8.0, especially if it triggers years and years of never-ending heated religious-style debate. It may well be possible to alter the design in a way that satisfies both camps, so it'd be a pity if this feature is released too early to allow that to happen.
oops, re arity, I mixed up |
Yes it does, but that assumes you know at that point that you need a full range. You can construct a range from arbitrary indexes and another part of the program may be determining that the end index is
The team has posted their meeting notes and discussed at some length how and why they came to the decision that they did. Framing it as some dichotomy between "best solution" vs. "extreme fanatical wish" demonstrates that you're not interested in a practical solution and is not at all a constructive avenue of dialog. The team didn't rush in with "oh it must be |
Well I'm sorry that my message came across like that, because that wasn't my intended meaning. I was trying to say in general that fanaticism is a problem that pops up sometimes, but I wasn't intending to say that it happened in this case, and I wasn't speaking about you. Maybe I failed to sufficiently clarify the part where I wrote "just speaking generally here".
Unfortunately I don't understand your point because you seem to be saying there is a lack of a way to specify an end, whereas I see that the proposal already includes
|
|
True, there is a mistake in my previous message. I incorrectly wrote
I shouldn't be trying to multitask, trying to discuss Range when actually I'm supposed to be working on something else this week. This multitasking leads to mistakes such as exchanging |
When you get some free time you can feel free to engage the Gitter community, which is better suited for a conversation on the subject. |
Yes so re syntax, my point is that
Overuse of symbols and overloaded context-sensitive meanings of preexisting symbols aren't good techniques in the design of a language. It is not a credible argument to claim that I really appreciated the improvements made in C# 7.x but this Range proposal bucks the trend. I'm sorry but the Range proposal really appears to be half-baked and not yet ready for C# 8.0. With some more work, it could become a great proposal, but it's not there yet. Major problems in the proposal include:
Thanks for suggesting Gitter and thanks for your replies. Overall the C# team has been doing a fantastic job, much appreciated, but nobody is capable of achieving 100% success rate, except for Superman, but he doesn't exist. |
You disagreeing with the proposal does not mean it's "half-baked" or not ready. Again, approaching the conversation like this is not productive. If you've already reached your conclusion without reading the relevant notes and are unwilling to consider other views then there's really nothing to discuss. Ranges have been a topic of discussion for years and the team has posted their notes which includes all sorts of variations on syntax and behavior, much of which was cut. The primary motivation for indexes and ranges is to facilitate slicing, and the behavior is oriented towards that motivation. That does not preclude further additions to the feature to come in the future.
The existing APIs already support extents just fine, and if you consider
Neither does
Lots of symbols and syntax in C# have multiple meanings based on context. As mentioned by the team, they chose
This is consistent with from-end or negative indexing in other languages. It's also the easiest way to handle the clusivity and directionality concerns that are inherent with ranges. I'd be very interested in seeing other languages that went a different direction, I've yet to find one.
I personally don't find
If every feature required unanimous support then the C# team would be currently achieving a 0% success rate. But their goal isn't to please everybody, it is to make pragmatic and long-term decisions that benefit the larger community. |
There are no 100% solutions here. We know this because we tried several approaches, and there was confusion with some groups with any particular approach. Furthermore, the approaches you seem to be suggesting would be inconsistent with the surrounding programming language ecosystem, which would be controversial in its own right. You need to distinguish between choices that you believe would be optimal for you, versus choices that are desirable for the entire ecosystem. |
Tough. The way the language is designed is not some: Feed inputs into Spock, and a logical result pops out. Instead, it's a group of humans with tons of combined experience under their belts designing, implementing and using a whole host of languages. They consider lots of options, debate for ages, and finally settle on a result they collectively feel provides the best combination of Pros/Cons. This assessment is ultimately personal and comes down to individual beliefs of relative value. You wanting that personal approach to not be here is not going to happen. |
Yes. It could. And that was considered and rejected for the initial release. What you seem to not be understanding is that in no way is this release consider the end-all-and-be-all for Ranges. This is what was felt to be a good initial foray into this space. We made it with complete awareness of the limitations and concerns here, and we designed it to be something we could improve upon in the future if it was felt to be important enough to do. This very topic was debated, and the LDM accepted that as a reaosnable starting point for 8.0. It won't be re-litigated. Maybe after 8.0 releases there will be enough feedback and use cases to make it so that they feel that handling both of these in-language is warranted. |
The C# team (and LDM) has never attempted to reach any sort of 100% success rate. That's not how languages work. Not only are there straight up mistakes in the language, but any particular feature added is known to not be sufficient for the entirety of our current (and our desired future) ecosystem and community. The goal is to add value and to provide features that are overall net positives. Not to hit any sort of arbitrary 100% success (however you would even measure that). |
Now that's unfair. I already changed my view in response to @Thaina's comment in a thread that you mentioned. I also expressed belief that a design exists that can make both camps happy.
I'd gladly write up a specific proposal and I have a design already in mind, but you guys are saying the issue is already closed, aren't you? @CyrusNajmabadi said "It won't be re-litigated" and @jnm2 said "very late". If you want the specific proposal from me, then I'd gladly do the work to write it up properly, but it sounds like you don't want it, or it won't make any difference because it's too late and you're all exhausted from debating the issue and the plan for C# 8.0 is already decided and won't be changed. The response that I've received here seems to be that the C# team is unwilling to consider other views at the current time because it's too late, therefore there's really nothing that I could write in my proposal that has any chance of acceptance, right? I'll do it if you want it, but please don't make me expend a big effort to write up a proper design document that will be immediately discarded. |
It's not closed until it's released. You mentioned language features around extents, and I want to see what specifically you mean. I feel that would be orthogonal to ranges as they are proposed here. If you have a different proposal for ranges you can feel free to open it, but you'll need to provide seriously compelling reasons for the C# team to reverse their decisions. |
Yes I have in mind a different design for the range feature, including the aim to support both extents and ranges equally well, considering that they're both useful in different circumstances. I cannot deliver a design document completely free of mistakes, but if people here take it seriously and develop the design further, then it could end up being a great proposal for ranges+extents as a team effort. Roughly how much time do I have remaining? The difficulty is that I would be unprofessional and irresponsible if I spend excessive time during weekdays to work on "X" when I already agreed to work on "Q", and I'm paid to work on Q not X. Unpaid work during the weekend is a possibility but won't succeed if it must be completed urgently. |
Can you give a rough sketch? What this would look like from the consumption perspective. How someone would use it in an API. And what the general semantics would be. It doesn't have to be perfect, but it would be helpful to have a better defined view of what you're thinking about. |
Very little. The team is heads down on getting 8.0 into a final shippable state. And most of the efforts are in very high risk, very high complexity areas (like Nullable). Given that the LDM is satisfied with both the expected shipping for for Ranges, as well as feeling that improvements could come in the future, it would be very challenging to change anything. That said, if your proposal was amazingly compelling, and went a direction that wasn't previously considered, and really solves a whole host of issues in a simple and effective way, it's always possible it woudl get attention. That's why i'd like to at least see a sketch of what you're thinking about. I could then say if it was something that had been considered during teh main design time for this feature. |
A rough sketch would be effective in the form of a .cs file that I upload somewhere, with the proposed language/syntax details in comments in corresponding places within the .cs file. Some people here have the luxury of being able to concentrate solely on the C# language design and get paid for it, but I do not have this luxury and unfortunately this timing conflicts with my obligations currently, thus uploading this proposal very quickly is impossible. As you guys have already indicated, it is irritating to receive vague critique without a concrete alternative proposal, and that's fair enough, but it also means that if I upload it too quickly, if I upload a sketch that is too rough, then it'll just be an irritating proposal containing too many mistakes on account on the rushed timeframe and conflicting work obligations. |
Sounds good.
I don't think either @HaloFour or I have that luxury. i don't think most of hte commenters here have that luxury. We all have day jobs that we have to focus on. But we do what we can to fit this sort of thing in. One thing you could consider would be taking this to gitter.im to have a better venue to explore your ideas (and potentially get people filling in gaps for you).
I'm really just trying to get a basic idea of what you're suggesting. THere's been a lot of talk about extents, and very little explanation of what that means at a language level, or how it would be affect the user programming model. |
I think if the current version of the Range feature is released as-is, then my design is dead forever because it is too different/incompatible to be implemented as an extension in future. Currently I don't see how the various kinds of slicing operations can be retrofitted into the current version of the proposal without much breaking of compatibility. |
Easy: just use different syntax. Now you have no chance of stepping on what's currently shipped and what teh semantics of it are. |
Sure, if it was only syntax, but I propose a different design for https://docs.microsoft.com/en-us/dotnet/api/system.range |
Why can't you have both these designs? IMO, it's akin to how Roslyn's TextSpan has a |
As requested, here's the rough sketch. I hope you all like it. With some teamwork, it can be further improved to make a really great extents/ranges/slicing/segments feature for C#. |
Any consideration for stepping? #2562 |
As I though all over this discussion, Range will be an IEnumerable. So you can have: foreach(int year in 2015..2019) { } |
Introduce a
..
syntax, such thatx..y
ends up creating aRange
ofx
andy
.See also
The text was updated successfully, but these errors were encountered: