4 ms·
I feel that 1-based indexing has been the right choice, and I am aware that many do not like it. I really haven't run into off-by-one issues much, but this is p
by ViralBShah 11y ago
I feel that 1-based indexing has been the right choice, and I am aware that many do not like it. I really haven't run into off-by-one issues much, but this is probably more about how one is used to writing code. I like that you can iterate over a vector of size n, by just going from 1 to n.
Coming from a regular programming background, as opposed to a technical computing background, can certainly make this look alien. However, I think it starts feeling natural quickly. There are many other things in Julia that can take a lot longer to get used to.
- gct 11y agoIt sucks for slicing though. In python (zero based), you can use 0:n to slice the entire array with a half-open interval. With one based, you have to either have a closed interval, so 1:n is the whole array (which sucks because what does an empty interval starting at 1 look like? 1:0?) Or you can have a half-open interval and index 1:n+1. I don't see what you saved yourself other than making things uglier.