4 ms·
I don't have a strong position on 0-based versus 1-based, but Dijkstra's argument does not make any sense to me. He says that expressions A ≤ x ≤ B, A < x ≤ B,
by IlliOnato 6y ago
I don't have a strong position on 0-based versus 1-based, but Dijkstra's argument does not make any sense to me.
He says that expressions A ≤ x ≤ B, A < x ≤ B, and A < x < B are confusing and a source of errors, but A ≤ x < B is not.
I really cannot understand what's the difference, and why one would be more mentally taxing than another.
(From that he concludes that iterating over 0-based array is more intuitive. This kinda/sorta makes sense, if you believe the initial premise).
I'd like someone to shed light on this, if possible.
- silon42 6y agoOne interesting case is when partitioning on integers, but wish to compare with floats... How do you get all values in say in 0..9.9999 when using 0 <= x <= 9... it makes sense to use 0 <= x < 10... Another case is when using datetime... how do you specify the whole day without knowing the precision of your datetime (seconds, milliseconds, nanoseconds...)... again, specifying 2021-01-10 to 2021-01-11 makes more sense than using 2021-01-10T23:59:59.999 for the upper boundary.
- lifthrasiir 6y ago> How do you get all values in say in 0..9.9999 when using 0 <= x <= 9... it makes sense to use 0 <= x < 10... This breaks down for negatives, though. -9.9999..0 would be -10 < x <= 0.
- mjevans 6y agoIt's just fine for negatives. If you slide the range that 'makes sense' back by 10 (add -10 to it): -10 <= x < 0 This excludes the end of the range, it includes the start of the range. What's changed is that the start of the range is no longer at zero and also has crossed from positive to negative.
- IlliOnato 6y agoI hope you are not iterating over floating point numbers between 0 and 9.9999 :-) But your example is just the case for using 0 <= x < 10 in that _particular_ case. However, if I want all numbers greater than zero and up to and including 10, I'd write 0 < x <= 10. So I fail to see your point. Do you argue that if we had to choose just one of these expressions, 0 <= x < 10 would have more utility? I don't know how to evaluate this conjecture, but suppose it's right. Why would you need to limit yourself to just one, though? Why not to use one that is most suitable to the problem you are dealing with?
- ookdatnog 6y agoHis argument works by exclusion; he excludes every notation that doesn't work with just the natural numbers. Using strict inequality for the lower bound means you can't express sequences starting at 0 without expressing your lower bound as a negative number, which is ugly. So he prefers non-strict inequality for the lower bound. Using non-strict inequality for the upper bound causes a similar problem. Consider the sequences (non-strict inequality on both sides) [0..2], [0..1], [0..0]. The first has three elements, the second two elements, the third one element. If you want to express a sequence with no elements starting at 0, that is impossible without using a negative number for the upper bound ([0..-1]). So he excludes using non-strict inequality for upper bounds. What we're left with is non-strict inequality for the lower bound and strict inequality for the upper bound. This way we never have to leave the set of natural numbers to express natural number sequences, and as an added bonus, the difference between our bounds is equal to the length of the sequence. Note that this part of the argument doesn't touch on 0 vs 1 yet, that is argued later in the essay.
- IlliOnato 6y agoAh, this makes some sense, thanks.