Skip to content

Add proposal for System.Index and System.Range#48

Merged
terrajobst merged 3 commits intodotnet:masterfrom
terrajobst:range-new
Dec 13, 2018
Merged

Add proposal for System.Index and System.Range#48
terrajobst merged 3 commits intodotnet:masterfrom
terrajobst:range-new

Conversation

@terrajobst
Copy link
Contributor

No description provided.

@terrajobst terrajobst force-pushed the range-new branch 2 times, most recently from 9fb4b0d to 7659764 Compare December 3, 2018 22:58
@poke
Copy link

poke commented Dec 3, 2018

I kind of missed the discussion where the syntax for from-the-end indexes was changed from negative indexes to ^ indexes, so I don’t know what has been said there. I do have a bit of a problem with the wording though.

An index “from end” suggests to me that I basically index the collection like normal but starting at the end. Since indexing starts at zero, ^0 should be the first element from the end, i.e. the last element. I totally get that ^1 should be length - 1, just like -1 in the old spec does (I actually still prefer that but I guess that has already been decided now), but I think the wording should be adjusted in some way.

@DustinCampbell
Copy link
Member

@poke: The C# LDM decided on ^ rather than - because it would be significant breaking change to use negative numbers. The problem is that a[-1] compiles and means something today -- it throws an exception, which the application might catch. It would be a major breaking change to stop throwing an exception and return a result that the application isn't expecting.

FWIW, this is the design that @MadsTorgersen and I showed demoed at Build back in May. The discussion thread for this is on the C# language design repo here: dotnet/csharplang#185. Here's a pointer to my comment describing the design decision: dotnet/csharplang#185 (comment).

@poke
Copy link

poke commented Dec 3, 2018

@DustinCampbell Ah, thanks a lot for the explanation and the pointers. That does make sense! :) I’ll read that other discussion later to catch up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants