|
|
|
|
|
by blt
3775 days ago
|
|
Here are some tasks that are ugly with [1:n] indexing: - the 1D index of element (i,j) in a matrix is i+(j-1)*m instead of i+j*m
- the i'th 3-element subvector of a vector is v[3*(i-1)+1:3*i]
instead of v[3*i:3*(i+1)]
- if you have vector of indices that partitions an vector into chunks,
the i'th chunk is v[ind[i]:ind[i+1]-1] instead of v[ind[i]:ind[i+1]]
Perhaps small issues, but these are all real examples from my most recent Matlab project that were annoying.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. |
|
>, my opinion on this topic is distorted because I spent a lot of time programming in C++
Mathematics-related programming[1] in MATLAB, R Language, Mathematica, SAS, etc all use 1-based indexing. Given that the originators of Julia are MATLAB users, it makes sense that they made a deliberate choice to keep 1-based indexing.
In other words, it was more important to grab mindshare from those previous math tools rather than appeal to C/C++/Java/etc programmers.
One outlier in the landscape of numerical programming is Python+NumPy/SciPy in the sense that it uses 0-based indices. While Julia also wants to be attractive to Python programmers, it still seems like the bigger motivation was programmers of MATLAB and other math software.
[1]https://www.youtube.com/watch?v=02U9AJMEWx0&feature=youtu.be...