[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Substring & friends
I object to changing the substring indexing scheme. I chose the
imbalanced inclusive-start/exclusive-end pair because it has a some
nice properties:
1. The pair for the entire string is (0, length(string)), which is
trivially computable.
2. The pair for the empty string is (i, i) for any i <=
length(string). There is no natural representation for this if both
indices are inclusive.
Don't think that no thought went into this. I know that on first
encountering this scheme it seems unintuitive, but experience has
shown it to be quite effective, and once learned, easy to remember.
I don't think that the issue of whether or not the end index is a
valid index for the string is very interesting. In practice, it is
easy to decide whether a given index pair is valid:
0 <= start <= end <= length(string)