# What are common mistakes in julia that beginners should aware of?

**URL:** <https://discourse.julialang.org/t/what-are-common-mistakes-in-julia-that-beginners-should-aware-of/51874>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [December 15, 2020, 2:21pm UTC](https://discourse.julialang.org/t/what-are-common-mistakes-in-julia-that-beginners-should-aware-of/51874 "2020-12-15T14:21:57Z")\
**Posts on this page:** 7\
**Page:** 4

<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:** [January 6, 2021, 12:57pm UTC](https://discourse.julialang.org/t/what-are-common-mistakes-in-julia-that-beginners-should-aware-of/51874/61 "2021-01-06T12:57:14Z")

</div>

I would like to point out that if your elements are not immutable and you change _inside_ them (not this specific case) `copy` is not enough, you need to use `deepcopy` to make a copy of each element (recursively).

---

<div class="post-metadata">

**Author:** ![bkamins](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bkamins/32/208538_2.png) [@bkamins](https://discourse.julialang.org/u/bkamins)\
**Post date:** [January 6, 2021, 1:17pm UTC](https://discourse.julialang.org/t/what-are-common-mistakes-in-julia-that-beginners-should-aware-of/51874/62 "2021-01-06T13:17:29Z")

</div>

The reason is that in general we have:

```julia
to_index(i::Bool) = throw(ArgumentError("invalid index: $i of type Bool"))

```

so `Bool` indexing should be disallowed. However, in Julia Base some methods have custom implementations of `getindex` that does not fall back to `to_index`.

---

<div class="post-metadata">

**Author:** ![lungben](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lungben/32/12314_2.png) [@lungben](https://discourse.julialang.org/u/lungben)\
**Post date:** [January 6, 2021, 1:32pm UTC](https://discourse.julialang.org/t/what-are-common-mistakes-in-julia-that-beginners-should-aware-of/51874/63 "2021-01-06T13:32:39Z")

</div>

It would be good to clean it up for Julia 2.0 (probably not possible before because it is technically breaking).  
Is there already an issue for it?

---

<div class="post-metadata">

**Author:** ![mcabbott](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mcabbott/32/6603_2.png) [@mcabbott](https://discourse.julialang.org/u/mcabbott)\
**Post date:** [January 6, 2021, 1:52pm UTC](https://discourse.julialang.org/t/what-are-common-mistakes-in-julia-that-beginners-should-aware-of/51874/64 "2021-01-06T13:52:49Z")

</div>

> [@rafael.guerra](#):
>
> why `true` is not interpreted as an integer in some cases?

I think the reason Bool doesn’t count as an integer for indexing purposes is to avoid confusing with logical indexing:

```julia
julia> v = ["a", "b"];

julia> v[[1, 1]] # vector of indices, also v[[1,2,1,2,1]] or v[[CartesianIndex(2)]]
2-element Vector{String}:
 "a"
 "a"

julia> v[[true, true]] # logical indexing, also v[v .== "a"]
2-element Vector{String}:
 "a"
 "b"

```

I presume that `Tuple(v)[true]` working is an oversight, since logical indexing does still work there: `Tuple(v)[[true, false]]`. Maybe [Tuple and NamedTuple indexing corner cases · Issue #29417 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/issues/29417) is the issue.

---

<div class="post-metadata">

**Author:** ![bkamins](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bkamins/32/208538_2.png) [@bkamins](https://discourse.julialang.org/u/bkamins)\
**Post date:** [January 6, 2021, 2:35pm UTC](https://discourse.julialang.org/t/what-are-common-mistakes-in-julia-that-beginners-should-aware-of/51874/65 "2021-01-06T14:35:01Z")

</div>

Yes, see [https://github.com/JuliaLang/julia/pull/31829](https://github.com/JuliaLang/julia/pull/31829) and [https://github.com/JuliaLang/julia/issues/31726](https://github.com/JuliaLang/julia/issues/31726)

---

<div class="post-metadata">

**Author:** ![logankilpatrick](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/logankilpatrick/32/38123_2.png) [@logankilpatrick](https://discourse.julialang.org/u/logankilpatrick)\
**Post date:** [September 20, 2022, 2:24pm UTC](https://discourse.julialang.org/t/what-are-common-mistakes-in-julia-that-beginners-should-aware-of/51874/66 "2022-09-20T14:24:14Z")

</div>

I tried to sum up a lot of the discussion that took place here in a single post, feel free to check it out and let me know if there are other things that should be added in a subsequent post: [Tricky concepts in Julia for beginners (and how to overcome them) | by Logan Kilpatrick | Sep, 2022 | Medium](https://logankilpatrick.medium.com/tricky-concepts-in-julia-for-beginners-and-how-to-overcome-them-46af1c514d50)

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [September 20, 2022, 2:43pm UTC](https://discourse.julialang.org/t/what-are-common-mistakes-in-julia-that-beginners-should-aware-of/51874/67 "2022-09-20T14:43:14Z")

</div>

Something on the lines of this would be useful as well: [Common allocation mistakes](https://discourse.julialang.org/t/common-allocation-mistakes/66127)

[Previous page](https://discourse.julialang.org/t/what-are-common-mistakes-in-julia-that-beginners-should-aware-of/51874.md?page=3)
