On Oct 24, 2007, at 7:45 PM, Steven D’Aprano wrote:
range(1, 5) => 1, 2, 3, 4
0…5 => 0, 1, 2, 3, 4, 5
find that having two operators … and … is a blessing, or a curse
because you can never remember which is which?
i use both frequently. ‘…’ is always leads to shorter code when
complex iterations are done and, of course, lead to fewer off by one
errors since ruby arrays are zero index based.
How useful are the closed interval forms? Do you find yourself
making off-
by-one errors or needing to increment/decrement variables by one?
no. but i’ve fixed alot of code that has.
range(start, end+1)
to avoid an off-by-one error. When I used to program in Pascal (which
exclusively uses closed intervals) I used to need to do it all the
time.
What’s the Ruby experience?
in my experience open intervals, in c, fortran, c++ and idl often
lead to off by one errors but, that being said, i think it’s less in
fortran because it uses ‘1’ based arrays. also, anyone whose has
coded C has probably found ‘off, length’ to be less error prone and
open intervals lend themselves more easily to that notion.
cheers.