[Numpy-discussion] Matlab page on scipy wiki

Gary Ruben gruben at bigpond.net.au
Fri Feb 10 19:42:00 CST 2006


Sasha wrote:
> On 2/10/06, Gary Ruben <gruben at bigpond.net.au> wrote:
>> ...  I must say that Travis's
>> example numpy.r_[1,0,1:5,0,1] highlights my pet hate with python - that
>> the upper limit on an integer range is non-inclusive.
> 
> In this case you must hate that an integer range starts at 0 (I don't
> think you would want len(range(10)) to be 11).

Actually, that wouldn't bother me and I'm not really fussed by whether a 
language chooses 0 or 1 based integer ranges, as long as you can 
override the default, but 0 seems more natural for any programming language.

 > If this is the case,
> I don't blame you: it is silly to start counting at 0, but
> algorithmically it is quite natural.  Semi-closed integer ranges have
> many algorithmic advantages as well such as length = (stop -
> start)/step,  empty range can be recognized by start=stop test
> regardless of step, adjacent ranges - start2=stop1 (again no need to
> know step) etc.

Thanks for the explanation Sasha. It does make some sense in terms of 
your examples, but I'll remain unconvinced.

>> I'm sure the BDFL has some excuse for this silliness.
> 
> Maybe he does not like Fortran :-)
> 
> PS: What's your second favorite language (I assume that python is the first :-)?

It's not Fortran-77! If I say it's Object Pascal (i.e. Delphi) you may 
begin to see where my range specifier preference comes from. Pascal lets 
you define things like enumeration type ranges like Monday..Friday. It 
would seem nonsensical to define the range of working weekdays as 
Monday..Saturday.

I'm pretty competent with C, less-so with C++ and I've totally missed 
out on Java. One day I might have a play with Haskell and Ruby. Actually 
I see that Ruby sidesteps my pet hate by providing both types of range 
specifiers. I can't see myself defecting to the enemy just because of 
this though,

Gary R.




More information about the Numpy-discussion mailing list