# Is OffsetArrays.jl a poison pill?

**URL:** https://discourse.julialang.org/t/is-offsetarrays-jl-a-poison-pill/85188
**Category:** Internals & Design
**Created:** [August 2, 2022, 7:22pm UTC](https://discourse.julialang.org/t/is-offsetarrays-jl-a-poison-pill/85188 "2022-08-02T19:22:53Z")
**Posts on this page:** 1
**Showing post:** 21

<div class="post-metadata">

### Author: ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)
#### Post date: [August 3, 2022, 8:36am UTC](https://discourse.julialang.org/t/is-offsetarrays-jl-a-poison-pill/85188/21 "2022-08-03T08:36:33Z")

</div>

> [@peterkovesi](#):
>
> How would we feel if an OffsetTuples.jl package was introduced

What sort of problems do you envision?

There’s no `AbstractTuple` type, so there’s no code that expects 1-indexed tuples, and could be surprised by 0-based tuple input. Only if a function accepts general iterables, could an `OffsetTuple` be used unexpectedly, and then the code must anyway deal with `OffsetArray`s, so you would need general indexing. I don’t think anyone would be bothered by someone registering OffsetTuples.jl.

The issue isn’t which packages exist, but what properties can you rely on for abstract types that you want to support. `Tuple`s do, but `AbstractArray` and iterables in general do not, guarantee 1-based indexing. It should therefore be as easy as possible to work with them, and mostly it is. `for a in A` is totally general; `eachindex(A)` is at least as simple as `1:length(A)`, certainly easier to type; `axis(A, 1)` is _simpler_ than `1:size(A, 1)`, etc. It’s when you don’t want to just loop over all elements that it gets a bit harder, then you have `begin`, `end`, `firstindex`, `lastindex`, `first`, `last`, …

But maybe there could be some very simple and universal way to get a one-based view into any `AbstractArray`? `OffsetArray` has `no_offset_view`, but should all `AbstractArray`s have a method like that? Then anyone who wants less hassle would just write

```julia
function foo(A0::AbstractArray)
    A = OneBasedView(A0)
    for i in 4:length(A)-3
        ...
    end
end

```

Could this be made even simpler? Could there be some way to facilitate automatic promotion to OneBased? A `@one_based` macro, a new _keyword_, `for1`? (just kidding, maybe.)

---

_[View the full topic](https://discourse.julialang.org/t/is-offsetarrays-jl-a-poison-pill/85188)._
