Today I found out something I always wondered about. Perhaps due to laziness, I never read further into it until now that I decided to count the items sectioned out in a substring or slice call. I always asked myself "What's the last item? Is it like arrays where you have to take one away to know?".
Let's make an example:
"small string".substring(0, 5)
Before, I would have said, "Ok, that's from 0 to 5. 0 1 2 3 4 5, that's 6 numbers, so are there 6 characters in that substring?"
If you try it, it returns "small". It's 5 letters. I knew this later on, but I never thought much about it. You just select the starting point and start counting characters from there and add that amount to the second argument (5 characters, 0 + 5, the second argument is 5).
But today I decided to see it a bit differently. I didn't count the characters but the places. It makes sense that if you want to be consistent, you won't have a function that takes two arguments being "arg1: starting place, arg2: count of characters after that" but something like "starting place, ending place". So, for the sake of consistency, I did the simple analysis. Let us count the number of section separators ( | ).
|s|m|a|l|l| |s|t|r|i|n|g|
If we count from 0 to 5, the first separator being "separator 0", there are indeed 6 separators. And the 6th separator would be the indicator of the 6th position character: the space (" "). One possible interpretation is that we include everything between the two separators counted, but I doubt that this is the interpretation that the compiler uses. The logical answer to this problem for my laybrain would be to indicate "starting position of first character, starting position of last character", but that is also obviously not the compiler's answer. What I think it does is taking the starting position of the first character and the ending position of the last character, that or the starting position of the character that will not be included.
So, I think that the two possible ways to interpret the last number would be either as the ending position of the last character, or the starting position of the first character.
And it sounds interesting to me to include a counter of what you're not going to include. It would be like having a ranking for "coolness" in the workplace and inviting everyone from the highest coolness until you get to Steven, and Steven is not cool, and everyone below him is not cool either, so you tell the inviter: "invite everyone in the list, but don't invite anyone starting from Steven". Or maybe more like: "start inviting and, when you see Steven, stop".
But this is not the most efficient way. I think that the precision of computing goes against a bit of Derrida's deconstruction. When I was learning C, I learned that computers have an assigned memory place for every bit of information. This would mean that the most likely interpretation for these numbers is the first one, where the first number represents the starting place of the first number, and the last number represents the ending place of the last number.
In the end, however, these are just ramblings and I have no idea what the intention of the creators was when they made this pattern of functions with starting and ending points in arrays and strings (the latter being sometimes seen as arrays of characters). I'm just having fun playing a little with my brain, which is my favourite toy nowadays.