News for hackers. Stuff that matters.
Re:GNU Octave by whatshisface on Saturday January 21, 2023 @05:18PM (#34471239)
That's so that range(10) has 10 items in it.
Re:GNU Octave by abdullahkhalids on Saturday January 21, 2023 @09:03PM (#34473360)
Yes. But when I use invoke range(k,n) or list[k:n] I intend to do operations on some specific items, not repeat some operations 10 times.

So every time I see `for i in range(10)`, I have to do the mental computation: I am repeating this operation on numbers from 0,...,9.

I would rather write `for i in range(9)` and know that I am operating on 0,..,9.

Re:GNU Octave by hgomersall on Sunday January 22, 2023 @02:58AM (#34475347)
For anyone that spends significant time using these languages, those mental mappings are as natural as the one you seem to think is obvious - then the additional advantages of the approach become apparent.

Exclusive upper bounds mean slices work neatly: a[0:10], a[10:20], a[20:30] etc. That's very neatly represented in a loop from zero in steps of ten. That pattern turns up all over the place when accessing arrays.

I've spent enough time in MATLAB to have been scarred by that kind of array slicing and off-by-one errors.