# Side effects of using a zero-based indexing package?

**URL:** <https://discourse.julialang.org/t/side-effects-of-using-a-zero-based-indexing-package/4451>\
**Category:** General Usage\
**Tags:** question\
**Created:** [June 25, 2017, 7:09pm UTC](https://discourse.julialang.org/t/side-effects-of-using-a-zero-based-indexing-package/4451 "2017-06-25T19:09:37Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![djsegal](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/djsegal/32/13752_2.png) [@djsegal](https://discourse.julialang.org/u/djsegal)\
**Post date:** [June 25, 2017, 7:09pm UTC](https://discourse.julialang.org/t/side-effects-of-using-a-zero-based-indexing-package/4451/1 "2017-06-25T19:09:37Z")

</div>

I saw @ChrisRackauckas starred a package on github recently about `2-based indexing`

// probably related to this ProgrammerHumor post:

[https://www.reddit.com/r/ProgrammerHumor/comments/6jea7z/array\_indexing\_round\_2/djdnjxi/](https://www.reddit.com/r/ProgrammerHumor/comments/6jea7z/array_indexing_round_2/djdnjxi/)

* * *

Going with it, I made a package that adds 0-based indexing to a module.

What are the downsides of using it? (i.e. the negative implications)

> **[GitHub - djsegal/ZeroBasedIndexing.jl: Zero-based indexing](https://github.com/djsegal/ZeroBasedIndexing.jl)**
>
> Zero-based indexing. Contribute to djsegal/ZeroBasedIndexing.jl development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![ScottPJones](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/scottpjones/32/146_2.png) [@ScottPJones](https://discourse.julialang.org/u/ScottPJones)\
**Post date:** [June 25, 2017, 7:36pm UTC](https://discourse.julialang.org/t/side-effects-of-using-a-zero-based-indexing-package/4451/2 "2017-06-25T19:36:06Z")

</div>

There is already Tim Holy’s OffsetArrays type, which is more general.  
It would be interesting to see a performance comparison between the two, when the OffsetArrays is using 0 for the offset,  
and seeing how either package fares against the “built-in” Julia Array type.

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [June 25, 2017, 8:05pm UTC](https://discourse.julialang.org/t/side-effects-of-using-a-zero-based-indexing-package/4451/3 "2017-06-25T20:05:47Z")

</div>

> **[Knowing where you are: custom array indices in Julia](https://julialang.org/blog/2017/04/offset-arrays/)**
>
> Knowing where you are: custom array indices in Julia | Arrays are a crucial component of any programming language,...

---

<div class="post-metadata">

**Author:** ![djsegal](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/djsegal/32/13752_2.png) [@djsegal](https://discourse.julialang.org/u/djsegal)\
**Post date:** [June 25, 2017, 10:42pm UTC](https://discourse.julialang.org/t/side-effects-of-using-a-zero-based-indexing-package/4451/4 "2017-06-25T22:42:04Z")

</div>

Don’t [OffsetArrays](https://github.com/JuliaArrays/OffsetArrays.jl) and this have different use cases?

- OffsetArrays is for compartamentalizing offsets in arrays
- [ZeroBasedIndexing](https://github.com/djsegal/ZeroBasedIndexing.jl) is for changing the offset globally throughout the module

One use case of ZeroBasedIndexing could be to make translating a python package easier

* * *

What I’m trying to ask is what weird complications come from doing this?

// e.g. do imported modules get messed up?

---

<div class="post-metadata">

**Author:** ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)\
**Post date:** [June 26, 2017, 3:46am UTC](https://discourse.julialang.org/t/side-effects-of-using-a-zero-based-indexing-package/4451/5 "2017-06-26T03:46:51Z")

</div>

Some issues with that implementation:

- Dictionaries are broken (as are any other data structures that use non-numeric keys)
- `end` is broken
- Cartesian indexing is broken
- `eachindex` is broken (as are any other functions that return a set of indices)
- `:` indexing is broken
- Logical indexing is broken
- `view` isn’t also zero-based

It doesn’t affect any other modules, though. Just the code you write within the module you use it in.

---

<div class="post-metadata">

**Author:** ![tim.holy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tim.holy/32/52_2.png) [@tim.holy](https://discourse.julialang.org/u/tim.holy)\
**Post date:** [June 26, 2017, 3:23pm UTC](https://discourse.julialang.org/t/side-effects-of-using-a-zero-based-indexing-package/4451/6 "2017-06-26T15:23:15Z")

</div>

For a better approach, you should use [CustomUnitRanges](https://github.com/JuliaArrays/CustomUnitRanges.jl) and exploit the `ZeroRange` type to create your own `ZArray{T,N} <: AbstractArray{T,N}`. See the code in [OffsetArrays](https://github.com/JuliaArrays/OffsetArrays.jl) for inspiration.

---

<div class="post-metadata">

**Author:** ![leiteiro](https://avatars.discourse-cdn.com/v4/letter/l/b5e925/32.png) [@leiteiro](https://discourse.julialang.org/u/leiteiro)\
**Post date:** [June 26, 2017, 4:50pm UTC](https://discourse.julialang.org/t/side-effects-of-using-a-zero-based-indexing-package/4451/7 "2017-06-26T16:50:16Z")

</div>

I really hope that one of the experts will work out this special case on the basis of Tim Holy’s modules!

---

<div class="post-metadata">

**Author:** ![tim.holy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tim.holy/32/52_2.png) [@tim.holy](https://discourse.julialang.org/u/tim.holy)\
**Post date:** [June 26, 2017, 5:14pm UTC](https://discourse.julialang.org/t/side-effects-of-using-a-zero-based-indexing-package/4451/8 "2017-06-26T17:14:08Z")

</div>

It’s actually a great exercise for someone who wants to make the transition `newbie => expert`. If you submit the package for inclusion in [JuliaArrays](https://github.com/JuliaArrays), I can promise you that you’ll get thorough code-review; it’s like having a professional consultant giving you free advice about how to become a better Julia programmer. Why on earth would an expert want to take such an opportunity away from someone? 🙂

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [June 26, 2017, 5:15pm UTC](https://discourse.julialang.org/t/side-effects-of-using-a-zero-based-indexing-package/4451/9 "2017-06-26T17:15:46Z")

</div>

> [@tim.holy](#):
>
> It’s actually a great exercise for someone who wants to make the transition newbie =\> expert. If you submit the package for inclusion in JuliaArrays, I can promise you that you’ll get thorough code-review; it’s like having a professional consultant giving you free advice about how to become a better Julia programmer. Why on earth would an expert want to take such an opportunity away from someone? 🙂

(taking notes from the expert on how to get contributors…)

---

<div class="post-metadata">

**Author:** ![tim.holy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tim.holy/32/52_2.png) [@tim.holy](https://discourse.julialang.org/u/tim.holy)\
**Post date:** [June 26, 2017, 5:19pm UTC](https://discourse.julialang.org/t/side-effects-of-using-a-zero-based-indexing-package/4451/10 "2017-06-26T17:19:49Z")

</div>

> [@ChrisRackauckas](#):
>
> (taking notes from the expert on how to get contributors…)

From what I can tell, you are expert at that particular skill already! Go, DiffEq!
