# How much can hard-coded indexing be avoided in Julia?

**URL:** <https://discourse.julialang.org/t/how-much-can-hard-coded-indexing-be-avoided-in-julia/55699>\
**Category:** Internals & Design\
**Created:** [February 20, 2021, 8:23pm UTC](https://discourse.julialang.org/t/how-much-can-hard-coded-indexing-be-avoided-in-julia/55699 "2021-02-20T20:23:42Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)\
**Post date:** [February 21, 2021, 12:50am UTC](https://discourse.julialang.org/t/how-much-can-hard-coded-indexing-be-avoided-in-julia/55699/8 "2021-02-21T00:50:48Z")

</div>

I did not say it in the exact post I linked above, but three posts below, and the the context is:

> [@Any shortcut to 1:length(myVector)?](https://discourse.julialang.org/t/any-shortcut-to-1-length-myvector/52816/30):
>
> if the code is guaranteed to not change too much (i.e., will keep using `Vector` s and not making so many accesses) then the decision ends up being mostly stylistic.

But yes, I would like to believe that given time (and that nothing changes in `Base`) more and more people will adopt one of that three alternatives (given their specific use). If you use only values, there really no reason to not go with just `for element in collection`; use only indexes? go with `for index in eachindex(collection)`; use both indexes and values? `for (index, element) in pairs(collection)`. There can be exceptions given some particular characteristics of your loop, but these should be considered the default in the mentioned circumnstances.

---

_[View the full topic](https://discourse.julialang.org/t/how-much-can-hard-coded-indexing-be-avoided-in-julia/55699)._
