I’d rather use OffsetArrays to guarantee I’m using 0-based arrays than alter my indexing.
Arrays with different indices often have different indices for a reason, so when I have to work with those I wouldn’t usually write indices that disregard that. That’s not really a dealbreaker though because when I need to disregard them, I would use begin
/end
, and using @absolutezero
is intended for the same thing with 0
/whatever. The bigger problem is that this doesn’t cover a lot of expressions I could put in the brackets. Here’s a simple one:
julia> x = 1:9
1:9
julia> x[begin] == x[begin .+ 0] # @absolutezero x[0]
true
julia> x[:] == x[:] # @absolutezero x[:]
true
julia> x[begin] == x[begin .+ begin] # @absolutezero x[begin]
false
begin
stands in for the method call firstindex(x)
, and I could be calling much more complicated methods to find an index. begin .+ some_method(x, inputs...)
isn’t always what I want (for example, if it returns :
), and it might not even be possible if addition is not defined for the indices type’s values.