|
Well, Julia is a language designed for mathematics, where indices starting at 1 is common (vectors, matrices). You can argue that polynomials have exponents starting at zero, but then you quickly get to Laurent polynomials, and what you really should be arguing is that the lower bound should be configurable, rather than being set at one specific value (which, of course, is still possible with custom types). Second, I don't find Guido's argument convincing. Yes, half-open ranges can be mathematically more elegant (and that's actually Dijkstra's argument), but that doesn't mean that the code necessarily becomes more readable. For example, to construct an array without the element at index i, you'd do the following with Python-style indexing: a[0:i] + a[i+1:n]
and the following with closed intervals and indexing starting at 1: a[1:i-1] + a[i+1:n]
While there is an element of subjectivity to it, I at least find the latter option more readable (possibly because of habituation to mathematical notation).While the notation for the specific example of i:i+k-1 might be less elegant with closed ranges, closed ranges are something that you find in every math textbook, because sums, products, unions, intersections from a to b (and other operators in that style) operate on closed ranges normally. Closed ranges are the norm in conventional mathematical notation and it makes sense to pick the option that minimizes the overhead when transcribing between mathematical texts and code. |
But maybe, like the static typing issue, my opinion on this topic is distorted because I spent a lot of time programming in C++ and comparatively little time reading math papers.
Or maybe it would be equally easy to make a list of tasks that are ugly with [0:n) indexing.