Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Python

Slicing history?

 

 

Python python RSS feed   Index | Next | Previous | View Threaded


aahz at pythoncraft

Nov 15, 2009, 10:50 AM

Post #1 of 6 (255 views)
Permalink
Slicing history?

Anyone remember or know why Python slices function like half-open
intervals? I find it incredibly convenient myself, but an acquaintance
familiar with other programming languages thinks it's bizarre and I'm
wondering how it happened.
--
Aahz (aahz [at] pythoncraft) <*> http://www.pythoncraft.com/

[on old computer technologies and programmers] "Fancy tail fins on a
brand new '59 Cadillac didn't mean throwing out a whole generation of
mechanics who started with model As." --Andrew Dalke
--
http://mail.python.org/mailman/listinfo/python-list


joncle at googlemail

Nov 15, 2009, 11:01 AM

Post #2 of 6 (242 views)
Permalink
Re: Slicing history? [In reply to]

On Nov 15, 6:50 pm, a...@pythoncraft.com (Aahz) wrote:
> Anyone remember or know why Python slices function like half-open
> intervals?  I find it incredibly convenient myself, but an acquaintance
> familiar with other programming languages thinks it's bizarre and I'm
> wondering how it happened.
> --
> Aahz (a...@pythoncraft.com)           <*>        http://www.pythoncraft.com/
>
> [on old computer technologies and programmers]  "Fancy tail fins on a
> brand new '59 Cadillac didn't mean throwing out a whole generation of
> mechanics who started with model As."  --Andrew Dalke

Good ol' zero based indexing. It makes a lot more sense that range(len
(my_list)) returns 'n' values which are valid indicies, otherwise
they'd be a lot of IndexError's being raised.

Besides, when you really want the full range (a corner case), it's a
lot easier to do a +1, than to force people to write -1 for the vast
majority of cases.

Jon.
--
http://mail.python.org/mailman/listinfo/python-list


nobody at nowhere

Nov 15, 2009, 11:19 AM

Post #3 of 6 (238 views)
Permalink
Re: Slicing history? [In reply to]

On Sun, 15 Nov 2009 10:50:43 -0800, Aahz wrote:

> Anyone remember or know why Python slices function like half-open
> intervals? I find it incredibly convenient myself, but an acquaintance
> familiar with other programming languages thinks it's bizarre and I'm
> wondering how it happened.

How else would they function? Closed intervals?

Using a closed interval (for just about anything) indicates that the
designer has very limited programming experience. Anyone with a modicum of
programming experience knows that half-open intervals are the norm, and
that using closed intervals will confuse anyone else with a modicum of
programming experience.

That's aside from the objective merits, i.e. the fact that they can be
used to partition an interval into subintervals without having to
adjust the upper bound (which requires knowing how much to adjust the
upper bound by, if that's even possible (for reals, it isn't)).

--
http://mail.python.org/mailman/listinfo/python-list


dickinsm at gmail

Nov 15, 2009, 12:11 PM

Post #4 of 6 (242 views)
Permalink
Re: Slicing history? [In reply to]

On Nov 15, 6:50 pm, a...@pythoncraft.com (Aahz) wrote:
> Anyone remember or know why Python slices function like half-open
> intervals?  I find it incredibly convenient myself, but an acquaintance
> familiar with other programming languages thinks it's bizarre and I'm
> wondering how it happened.

Sounds like an excuse to post this Dijkstra link:

http://www.cs.utexas.edu/~EWD/ewd08xx/EWD831.PDF

--
Mark
--
http://mail.python.org/mailman/listinfo/python-list


showell30 at yahoo

Nov 15, 2009, 12:40 PM

Post #5 of 6 (235 views)
Permalink
Re: Slicing history? [In reply to]

On Nov 15, 12:11 pm, Mark Dickinson <dicki...@gmail.com> wrote:
> On Nov 15, 6:50 pm, a...@pythoncraft.com (Aahz) wrote:
>
> > Anyone remember or know why Python slices function like half-open
> > intervals?  I find it incredibly convenient myself, but an acquaintance
> > familiar with other programming languages thinks it's bizarre and I'm
> > wondering how it happened.
>
> Sounds like an excuse to post this Dijkstra link:
>
> http://www.cs.utexas.edu/~EWD/ewd08xx/EWD831.PDF
>

That is really good stuff! Like Aahz I have Python's slicing
mechanism (and zero-based indexing) burnt into my brain, but I never
had a good way to explain why it makes sense, other than just an
intuitive notion that it works for me. It is interesting how the link
actually seems to explain zero-based indexing as a consequence of the
slicing approach, not a cause. I always understood zero-based
indexing as a relic of memory management, which was fine, but I guess
the reasons go deeper than that.




--
http://mail.python.org/mailman/listinfo/python-list


aahz at pythoncraft

Nov 15, 2009, 2:06 PM

Post #6 of 6 (236 views)
Permalink
Re: Slicing history? [In reply to]

In article <667394cb-d505-4906-8c6b-ab2d361b3a4d [at] j24g2000yqa>,
Mark Dickinson <dickinsm [at] gmail> wrote:
>On Nov 15, 6:50=A0pm, a...@pythoncraft.com (Aahz) wrote:
>>
>> Anyone remember or know why Python slices function like half-open
>> intervals? =A0I find it incredibly convenient myself, but an acquaintance
>> familiar with other programming languages thinks it's bizarre and I'm
>> wondering how it happened.
>
>Sounds like an excuse to post this Dijkstra link:
>
>http://www.cs.utexas.edu/~EWD/ewd08xx/EWD831.PDF

Many thanks!
--
Aahz (aahz [at] pythoncraft) <*> http://www.pythoncraft.com/

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are, by
definition, not smart enough to debug it." --Brian W. Kernighan
--
http://mail.python.org/mailman/listinfo/python-list

Python python RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.