Andrej Mitrovic: > Honestly, I think this would just encourage writing sloppy code.
I don't believe this, on the other hand I believe the current behaviour is bug-prone. > Using min(x, $) explicitly informs the reader of the code of exactly > what happens. Right. The problem is that in some cases you may forget to add that min(x, $). > It's harder to tell when it's implicit. Slicing syntax is used all the time in both Python and D code, so the Python and D programmers learn quickly and keep in mind what it does. Implicit behaviours are a problem when they are uncommon things, or library functions, etc, much less when they are built-in safety nets you use every five lines of code :-) Not only that, > but it can introduce bugs in your code - because while you might use > any upper bound, you're still not allowed to index beyond the length > of the array. Writing hundreds of thousands of lines of Python code I've seen that the saturating semantics we are talking about is not bug-prone (in fact it avoids some bugs). > Imagine this could was accepted by DMD: > > void main() > { > auto userArgs = ["foo"]; // runtime arguments by some user input > > auto firstTwo = userArgs[0..2]; // accepted by the new language change, > // implicitly > changes 2 to min(2, $) > > // more code here > > firstTwo[1] = "test"; // oops! > } Programmers just quickly learn that indexes and slices have a bit different semantics. Bye, bearophile