Hacker News new | past | comments | ask | show | jobs | submit login

Julia and Fortran, languages designed to be used for mathematics and high performance scientific computing, take a similar approach in the language itself and support arbitrary starting indices for arrays. Sometimes the math is just cleaner when the index starts at 0, or 1, or 2, or -1!

https://docs.julialang.org/en/v1/devdocs/offset-arrays/




Julia (normally 1-based), Polynomials package:

    julia> using Polynomials
    julia> p = Polynomial([1, 0, 2])
    Polynomial(1 + 2*x^2)

    julia> p[0]
    1
As long as it is domain specific and wrapped in custom types I don't really see an issue.


And of course there is C++ libraries to do the same. For example the blitz++ library. Negative indices to the left of element[0] are great for ghost zones in codes that do domain decomposition over different MPI ranks.




Consider applying for YC's W25 batch! Applications are open till Nov 12.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: