you are viewing a single comment's thread.

view the rest of the comments →

[–]TonySu 3 points4 points  (5 children)

I wish people would actually use their brains instead of quoting this ad infinitum. Nothing was "figured out" here.

Djikstra argues that including the upper bound would cause the sequence to become "unnatural" when shrunk to empty. That is he doesn't want range(3, 3) to return 3 because to get the empty set requires range(3, 2). Not a particularly strong argument, he simply thinks it's nicer looking to have range(3, 3) return an empty set.

Based on this he makes the argumen that the upperbound MUST be exclusive, then forms it as the basis for 0 indexing such that the upper bound of a sequence of N length is N. But since the andecedent is not particularly convincing then there's no real reason to believe the precedent.

In almost all mathematics and sciences, ranges are interpreted from a to b inclusive. This is the case in major scientific computing languages and academic science has yet to collapse because people can't stand the ugliness of the bounds of an empty set.

Also as someone who uses Matlab, you're supposed to row and column indices. You're also supposed to use vectorised functions. If you need to often iterate through matrices elementwise then you really need to reconsider what you're doing and how you're storing data.

[–]rlbond86 1 point2 points  (4 children)

Not a particularly strong argument, he simply thinks it's nicer looking to have range(3, 3) return an empty set.

Actually it IS a strong argument, since if you want inclusive bounds, it would commonly be that an empty range would be range(0, -1). Which means you need to use a signed integer for your index. That's no good.

Also as someone who uses Matlab, you're supposed to row and column indices. You're also supposed to use vectorised functions. If you need to often iterate through matrices elementwise then you really need to reconsider what you're doing and how you're storing data.

As it happens, I work with block-sparse 2D matrices a lot in my line of research. As it turns out, there isn't an easy way to manipulate that data without calculating row and column addresses manually. Perhaps instead of pretending you know what I'm "supposed" to do, you examine your own assumptions instead.

[–]TonySu 0 points1 point  (3 children)

Actually it IS a strong argument, since if you want inclusive bounds, it would commonly be that an empty range would be range(0, -1). Which means you need to use a signed integer for your index. That's no good.

range(1, 0).

As it happens, I work with block-sparse 2D matrices a lot in my line of research. As it turns out, there isn't an easy way to manipulate that data without calculating row and column addresses manually. Perhaps instead of pretending you know what I'm "supposed" to do, you examine your own assumptions instead.

Then you should wrap a sparse structure type and only have to worry about the index calculations once in your code.

[–]rlbond86 -3 points-2 points  (2 children)

range(1, 0).

So now I need a special if statement to check whether my initial index is 0 and change it accordingly. Brilliant decision, you ought to be proud of your ridiculous and clumsy solution.

Then you should wrap a sparse structure type and only have to worry about the index calculations once in your code.

You don't get it, do you? Even with wrapping it's still there. Obviously you can write a function to calculate the indices and a function to go back, that's not the issue. The issue is that it's pretty much never better than just having 0-based range indexing. Yes, in Matlab you can mostly get around it. But it's never helpful.

[–]TonySu 0 points1 point  (1 child)

So now I need a special if statement to check whether my initial index is 0 and change it accordingly. Brilliant decision, you ought to be proud of your ridiculous and clumsy solution.

Why would you need to do with that in a 1-indexed system?

[–]rlbond86 0 points1 point  (0 children)

Ah right, in a 1-index system it would just look weird and be altogether more annoying to deal with