6 ms·
It's not like it's the first. Doesn't Fortran default to 1-based? R and Matlab are also 1-based. Julia like those two are aimed at a mathematical domain, not ze
by goatlover 9y ago
It's not like it's the first. Doesn't Fortran default to 1-based? R and Matlab are also 1-based. Julia like those two are aimed at a mathematical domain, not zero-based offsets.
Anyway, it's not hard to get used to.
- civility 9y agoA bunch of wrongs don't make a right :-) And honestly, it's because I do numerical programming that I value zero-based offsets. In addition to subscripting arrays (which I could do in any base), I use those subscripts in the math itself. For instance, the zeroth bin of an FFT indicates the zero frequency. I also choose the zeroth array element to represent the constant term (zeroth power) of a polynomial, and so on. The common places where math notation uses 1-based subscripts (matrix notation) have more to do with people saying "first", "second", etc... With a few exceptions (the Hilbert matrix comes to mind), the base of the subscript isn't actually relevant to the math itself.
- dnautics 9y agoGenerally math formulae are one based, the fft and the Taylor expansions being the major exception. Natural numbers, by convention, unless you're bourbaki, start at one. I do appreciate that zero is easier because of offset caluculations, but you really do get used to it and in most cases the compiler figures it out with almost no penalty.
- civility 9y ago> Generally math formulae are one based, the fft and the Taylor expansions being the major exception. What formulas do you regularly use which benefit from being 1-based? Note, I'm not asking for instances where the index doesn't really matter and the author of a paper simply chose base-1. There are clearly cases where zero based is more natural. But I don't regularly use any cases where one based is an improvement. I will admit that zero-based adds a lot of confusion when communicating to other people.
- oneweekwonder 9y ago> A bunch of wrongs don't make a right :-) Funny how I always thought zero-based numbering[0] was a hack. Just in computer science a hack will become the right way? Any other fields where hacks became the new norm due to technical restrictions? Your statement is a opinion. To add to the list of languages using arrays in a "gross" way: pgsql, pascal, lua. [1]: https://en.wikipedia.org/wiki/Zero-based_numbering#Origin https://en.wikipedia.org/wiki/Zero-based_numbering#Origin
- kmill 9y agoThe way I've thought about this is that it's about whether an index is the name or the offset of an element of an array. Indices have a torsor-like structure, where you can subtract indices i and j to get an offset j-i from index i, and there is the relationship a[j] == a[i + (j-i)]. Zero-indexing is the special case that the name is the offset from the first element. Because of this, I figure any language that supports 1-indexing should also support arbitrary ranges for the indexing, like in Ada. (Basically, what's so special about 1?)
- groundCode 9y agoI always thought it neatly mimicked the way we think of age. When you are born you start at 0. You only turn 1 after you have lived a year.
- smt88 9y agoThat's an argument for starting at 1, not at 0. At age 0, you have no elements in your array of years. So the first year is also element 1. If you want code to reflect the way you've done counting and arithmetic your whole life, you'd want it to start at 1.
- crangos 9y agoThat would be defining it as a time span and using the time since start as index. Which to me is one step away from using the timepoint as the index iteself (zero as start), verus (1 year from zero). How would you index the time before the first birthday?
- simonbyrne 9y agoOriginally, FFTs were the only time I missed 0-based indexing in Julia. But the neat FFTViews.jl package (https://github.com/JuliaArrays/FFTViews.jl https://github.com/JuliaArrays/FFTViews.jl) addresses this, and even improves on it by letting you use periodic indices avoiding the need for functions like fftshift.
- bigiain 9y ago"Should array indices start at 0 or 1? My compromise of 0.5 was rejected without, I thought, proper consideration." -- Stan Kelly-Bootle
- bigiain 9y agoAlso: $[ = 1; (Yes, I'm _old_...)
- Thetawaves 9y agoAnd don't forget the venerable: $| = 1;
- thelastidiot 9y agohttps://en.wikipedia.org/wiki/Comparison_of_programming_languages_%28array%29#Array_system_cross-reference_list https://en.wikipedia.org/wiki/Comparison_of_programming_lang...