Range notation
-
As several other have pointed out this is standard mathematical notation, I remember seeing it in my mathematics courses for my degree, so at least on this side of the river (Mexico) it exists, however as a programmer I have never used it to describe anything, and i'm pretty sure that my ex classmates don't even remember what this is for. So answering your question in programming is not very common, but in mathematics it's.
CEO at: - Rafaga Systems - Para Facturas - Modern Components for the moment...
Thanks for your reply. Coming from Germany (and - of course - using a german keyboard layout) for me it's more than just confusing, because: ')' is SHIFT+9 ']' is ALTGR+9 So there is naturally a doubt if the ')' is intended or a typo ...
-
Klaus-Werner Konrad wrote:
‘‘the index must be in the [0 : size()) range,’’
His reply to my question about this discrepance was (as I asked for) that I'm missing that it is 'common (at least in US) a Notation for 'open range''; what's quiet not definite - it's a 'right open range'.
Ah, but its not an open range. Stroustrup expressed it exactly correctly -- its a range inclusive of the value 0, and exclusive of the value "size()" . If you're bounds checking access to an array, that's exactly the correct range check to make on the index. The parenthesis/square-bracket notation is indeed a standard mathematical notation for expressing the inclusive/exclusiveness of the range endpoints. Like you, I find the notation confusing. Despite reading it and using it myself countless times, I still have to look it up to make sure I use the correct bracketing. I do it because the notation is compact enough to include in the description of a function parameter, where popup documentation tips (a la intellisense) can present it to the next programmer while they're writing their code.
We can program with only 1's, but if all you've got are zeros, you've got nothing.
Ok, you're right, I was not precise enough... It's not a open range, but a half-open range, or, to be really precise, a 'right half open interval' Look at: https://en.wikipedia.org/wiki/ISO_31-11[^]
-
I think the [0, size()) makes sense. What I want to know is why he wrote size() <= i I would have written i >= size() was he trying to show that i was to the right of the valid range? Or maybe he reads right to left from the close parenthesis? Reading right to left on size() <= i makes more sense to me. This looks like it is talking about C++. Many loops are written with an "open interval" sequence that terminates when you pass the end of the valid interval and reach the "undefined/inaccessible" end() marker. for (itr = ..initialize..; itr != the.end(); ..advance..) { .. do the work .. } I always thought this looping structure was kind of like these driving directions: "Drive straight until you see empty air in front of you, then take a left at the top of the cliff" but it is an easy metaphor to implement for almost any container.
I always used
for (i=0; i< Size(); i++)
from the logical POV, but in reality I prefer
int sz = size;
for (i=0; i < sz; i++)to avoid the function call overhead in every condition check
-
Ok, you're right, I was not precise enough... It's not a open range, but a half-open range, or, to be really precise, a 'right half open interval' Look at: https://en.wikipedia.org/wiki/ISO_31-11[^]
Wow. Referring to that kind of range as an "open" range was not the terminology I expected. I was so sure it meant one end of the range was unbounded, that I didn't actually go read that terminology page until you replied.. so thanks for taking the time to reply -- I learned something today.
We can program with only 1's, but if all you've got are zeros, you've got nothing.
-
Interesting - I'm from Germay, too... But my time in scool was 'til 1976, maybe things (and stuff to learn) changed since then
That is one possibility. There are several others: - Either you forgot (if you do not need it, you will simply forget it) - It is state dependent (rumors are that in Bavaria school is the "best", but I do not know if that has ever been correct) - Your school focused on something different (I went to a school with mathematics as primary direction) Either way - don't worry about it :)
-
Thank you very much for your helpful comment :rolleyes: