|laziness, impatience, and hubris|
Re^4: Perl vs. Python for prime numbersby eyepopslikeamosquito (Chancellor)
|on Jun 15, 2013 at 09:23 UTC||Need Help??|
...the range built-in in Python excludes the upper bound. Makes sense from a mathematical point of view (combining different ranges is easier) but I prefer the more intuitive Perl way to do it.
Theoretically, I prefer semi-open ranges [begin, end), aka half-open intervals, because:
In practice, I prefer Python semi-open ranges to the inclusive (closed) ranges emitted by the Perl and Ruby range operator. I remember finding Python's semi-open ranges nicer when golfing with string slices. After enjoying Python string slices, I miss them when coding in Perl; the closest Perl equivalent, the substr function, seems unwieldy by comparison.
Semi-open ranges also feel comfortable to me because they form a crucial part of C++ STL, in particular iterators, which in turn were influenced by C pointers and arrays. Stepanov extended some common (semi-open) C idioms, such as:
inventing a more general iterator abstraction:
thus enabling STL algorithms to work on any container that implements the iterator interface.