Why Python does *SLICING* the way it does??

Steve Holden steve at holdenweb.com
Thu Apr 21 06:06:27 EDT 2005


beliavsky at aol.com wrote:
> Terry Hancock wrote:
> 
> <snip>
> 
>>So I like Python's slicing because it "bites *less*" than intervals
> 
> in C or Fortran.
> 
> I disagree. Programming languages should not needlessly surprise
> people, and a newbie to Python probably expects that x[1:3] =
> [x[1],x[2],x[3]] . Array-oriented languages, such as Fortran 90/95,
> Matlab/Octave/Scilab, and S-Plus/R do not follow the Python convention,
> and I don't know of Fortran or R programmers who complain (don't follow
> Matlab enough to say). There are Python programmers, such as the OP and
> me, who don't like the Python convention. What languages besides Python
> use the Python slicing convention?
> 
The principle of least surprise is all very well, but "needless surprise 
of newbies" is a dangerous criterion to adopt for programming language 
design and following it consistently would lead to a mess like Visual 
Basic, which grew by accretion until Microsoft realized it was no longer 
tenable and broke backward compatibility.

> Along the same lines, I think the REQUIREMENT that x[0] rather than
> x[1] be the first element of list x is a mistake. At least the
> programmer should have a choice, as in Fortran or VBA. In C starting at
> 0 may be justified because of the connection between array subscripting
> and pointer arithmetic, but Python is a higher-level language where
> such considerations are less relevant.
> 
But Pythonicity required that there should be one obvious way to do 
something. How obvious is having two ways? Then when you read code you 
would continually be asking yourself "is this a one-based or a 
zero-based structure?", which is not a profitable use of time.

regards
  Steve
-- 
Steve Holden        +1 703 861 4237  +1 800 494 3119
Holden Web LLC             http://www.holdenweb.com/
Python Web Programming  http://pydish.holdenweb.com/




More information about the Python-list mailing list