# 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:** 20\
**Page:** 3

<div class="post-metadata">

**Author:** ![vedasulo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vedasulo/32/20324_2.png) [@vedasulo](https://discourse.julialang.org/u/vedasulo)\
**Post date:** [December 16, 2020, 3:02pm UTC](https://discourse.julialang.org/t/what-are-common-mistakes-in-julia-that-beginners-should-aware-of/51874/41 "2020-12-16T15:02:53Z")

</div>

🙂 , I also had hate on oop. Although used alot, I personally felt very un-understandable. I used to use classes instead of functions without much knowing , Just to show recuiter.  
**But i am afraid how would it be used in giant software development and ml things.**  
I am probably thinking, **Julia may have initialized a new form of OOP idea which is powerful than OOP.** 🙂 . **thinkjulia** helped me alot and i have came to functions and will about to finish basis of it 🙂 Also,

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [December 16, 2020, 3:11pm UTC](https://discourse.julialang.org/t/what-are-common-mistakes-in-julia-that-beginners-should-aware-of/51874/42 "2020-12-16T15:11:44Z")

</div>

> [@paulmelis](#):
>
> Julia is fundamentally a different beast than e.g. Python

I think that explaining that in any meaningful way (_how_ it is different, really, for the purposes of the programmer who aims to write performant, idiomatic Julia code) just amounts to at least 70% of the manual.

Also, a reasonable reader should just assume that _any_ two programming languages are fundamentally different (unless stated otherwise, eg because one was derived from another). I am not sure the manual should belabor this point.

> [@paulmelis](#):
>
> You can obviously draw that conclusion yourself from the other chapters

Yes. This is what I am suggesting. My point is that there isn’t any shortcut around this, and assuming that one can skip the manual is a common mistake.

---

<div class="post-metadata">

**Author:** ![tbeason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tbeason/32/15898_2.png) [@tbeason](https://discourse.julialang.org/u/tbeason)\
**Post date:** [December 16, 2020, 3:17pm UTC](https://discourse.julialang.org/t/what-are-common-mistakes-in-julia-that-beginners-should-aware-of/51874/43 "2020-12-16T15:17:27Z")

</div>

I think I have a slightly different take on the original question. It is based on a false premise in my opinion. I do not think that anybody telling you “things you should be aware of” is going to help you learn to code in Julia (or any language). Beyond superficial differences in syntax, you will likely forget/not internalize most of what you are told until _you see it for yourself_. Repetition is key. You should not just read the Docs. You should code with the Docs always open. Code. Docs. Code Docs. Then you will know. This is the way of the Julian.

---

<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:** [December 16, 2020, 3:39pm UTC](https://discourse.julialang.org/t/what-are-common-mistakes-in-julia-that-beginners-should-aware-of/51874/44 "2020-12-16T15:39:27Z")

</div>

> [@tbeason](#):
>
> Code. Docs. Code Docs.

and Discourse. Because this forum is really great. I cannot express enough my gratitude to everyone that helped me along this year.

---

<div class="post-metadata">

**Author:** ![vedasulo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vedasulo/32/20324_2.png) [@vedasulo](https://discourse.julialang.org/u/vedasulo)\
**Post date:** [December 16, 2020, 3:47pm UTC](https://discourse.julialang.org/t/what-are-common-mistakes-in-julia-that-beginners-should-aware-of/51874/45 "2020-12-16T15:47:45Z")

</div>

> [@tbeason](#):
>
> I think I have a slightly different take on the original question. It is based on a false premise in my opinion. I do not think that anybody telling you “things you should be aware of” is going to help you learn to code in Julia (or any language).

I’ve got valuable resources by real Julian developers,  
from here instead of following or searching online through difference that people wrote (from outdated version). I was also able to get resources, that are beneficial to me.  
Got a very interesting ideas , ways, links. I am sure, other beginners if found hard will be able to found some good materials from these discussion.

But although,Your answer made solution, which is good in another sense.  
I should be now doing some real world project to get grasp 🙂 instead of doing basis things as previous developer.

My question was also trying to tell that instead of reading whole material and got some reading materials that I am just (maybe) able learn julia basis in few days. :

Thank you . 🙂

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [December 16, 2020, 4:21pm UTC](https://discourse.julialang.org/t/what-are-common-mistakes-in-julia-that-beginners-should-aware-of/51874/46 "2020-12-16T16:21:06Z")

</div>

This is the way.

---

<div class="post-metadata">

**Author:** ![DaveMacMahon](https://avatars.discourse-cdn.com/v4/letter/d/9f8e36/32.png) [@DaveMacMahon](https://discourse.julialang.org/u/DaveMacMahon)\
**Post date:** [December 17, 2020, 12:19am UTC](https://discourse.julialang.org/t/what-are-common-mistakes-in-julia-that-beginners-should-aware-of/51874/47 "2020-12-17T00:19:08Z")

</div>

`2.0f` is equivalent to `2.0 * f` in Julia

---

<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:** [December 17, 2020, 1:56am UTC](https://discourse.julialang.org/t/what-are-common-mistakes-in-julia-that-beginners-should-aware-of/51874/48 "2020-12-17T01:56:13Z")

</div>

> [@paulmelis](#):
>
> Vectors of `Bool` show `0` and `1` elements values when printed instead of `true` and `false` , leading you to believe that the values are of type integer

Well…

```julia
julia> supertype(Bool)
Integer

```

`Bool` is a type of `Integer` (i.e., the abstract type) in Julia.

But I understand your annoyance. If you see numbers without decimal places it is easy to assume `Int` and not to think of `Bool`.

---

<div class="post-metadata">

**Author:** ![paulmelis](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/paulmelis/32/35063_2.png) [@paulmelis](https://discourse.julialang.org/u/paulmelis)\
**Post date:** [December 17, 2020, 6:46am UTC](https://discourse.julialang.org/t/what-are-common-mistakes-in-julia-that-beginners-should-aware-of/51874/49 "2020-12-17T06:46:29Z")

</div>

> [@Henrique\_Becker](#):
>
> ```julia
> julia> supertype(Bool)
> Integer
> 
> ```
> 
> `Bool` is a type of `Integer` (i.e., the abstract type) in Julia.
> 
> But I understand your annoyance. If you see numbers without decimal places it is easy to assume `Int` and not to think of `Bool` .

It’s also the inconsistency compared to singular values:

```julia
julia> x = true
true

julia> typeof(x)
Bool

julia> x
true

julia> x = Bool[true, false]
2-element Array{Bool,1}:
 1
 0

julia> x[1]
true

```

---

<div class="post-metadata">

**Author:** ![carstenbauer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/carstenbauer/32/4981_2.png) [@carstenbauer](https://discourse.julialang.org/u/carstenbauer)\
**Post date:** [December 17, 2020, 7:40am UTC](https://discourse.julialang.org/t/what-are-common-mistakes-in-julia-that-beginners-should-aware-of/51874/50 "2020-12-17T07:40:37Z")

</div>

FWIW, I consider this a feature rather than an inconsistency.

---

<div class="post-metadata">

**Author:** ![paulmelis](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/paulmelis/32/35063_2.png) [@paulmelis](https://discourse.julialang.org/u/paulmelis)\
**Post date:** [December 17, 2020, 8:10am UTC](https://discourse.julialang.org/t/what-are-common-mistakes-in-julia-that-beginners-should-aware-of/51874/51 "2020-12-17T08:10:54Z")

</div>

Feature in what way? What’s the advantage?

---

<div class="post-metadata">

**Author:** ![carstenbauer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/carstenbauer/32/4981_2.png) [@carstenbauer](https://discourse.julialang.org/u/carstenbauer)\
**Post date:** [December 17, 2020, 8:29am UTC](https://discourse.julialang.org/t/what-are-common-mistakes-in-julia-that-beginners-should-aware-of/51874/52 "2020-12-17T08:29:25Z")

</div>

```julia
julia> X = rand(["true", "false"],10,10)
10×10 Array{String,2}:
 "false" "true" "false" "false" "true" "false" "false" "true" "true" "true"
 "false" "false" "false" "false" "false" "true" "true" "false" "false" "true"
 "false" "false" "false" "true" "false" "false" "false" "false" "false" "true"
 "true" "true" "false" "false" "true" "false" "true" "true" "false" "false"
 "false" "true" "false" "false" "false" "true" "true" "false" "false" "true"
 "false" "false" "false" "false" "true" "false" "false" "false" "false" "false"
 "true" "false" "false" "false" "false" "true" "false" "true" "true" "false"
 "false" "true" "false" "false" "false" "true" "false" "true" "true" "false"
 "false" "false" "true" "false" "true" "true" "true" "true" "true" "false"
 "true" "true" "false" "false" "false" "true" "true" "true" "true" "false"

julia> map(x->x=="true", X)
10×10 Array{Bool,2}:
 0 1 0 0 1 0 0 1 1 1
 0 0 0 0 0 1 1 0 0 1
 0 0 0 1 0 0 0 0 0 1
 1 1 0 0 1 0 1 1 0 0
 0 1 0 0 0 1 1 0 0 1
 0 0 0 0 1 0 0 0 0 0
 1 0 0 0 0 1 0 1 1 0
 0 1 0 0 0 1 0 1 1 0
 0 0 1 0 1 1 1 1 1 0
 1 1 0 0 0 1 1 1 1 0

```

I consider the latter to be **much easier** to parse. Also, the identification of `true` and `1` is not an invention by Julia. It is very much common in a theoretical computer science context.

Note that switching representations to improve readability is great and also utilised in many other contexts as well. In Julia 1.6 for example, you will see that the style of printing a sparse matrix depends on its size:

 ![Screenshot 2020-12-17 at 09.20.22](https://global.discourse-cdn.com/julialang/original/3X/2/c/2caacc653073732439dcca8d51de2430b2d67be4.jpeg)

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [December 17, 2020, 8:29am UTC](https://discourse.julialang.org/t/what-are-common-mistakes-in-julia-that-beginners-should-aware-of/51874/53 "2020-12-17T08:29:37Z")

</div>

> [@paulmelis](#):
>
> It’s also the inconsistency compared to singular values

That’s just how they are printed in a compact form.

---

<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:** [December 17, 2020, 9:22am UTC](https://discourse.julialang.org/t/what-are-common-mistakes-in-julia-that-beginners-should-aware-of/51874/54 "2020-12-17T09:22:14Z")

</div>

It’s possible that this compact printing should be turned off for vectors? E.g.:

```julia
julia> rand(ComplexF64, 2, 4) # Compact printing 
2×4 Matrix{ComplexF64}:
 0.471554+0.731366im 0.832658+0.694934im 0.21162+0.420378im 0.558943+0.646677im
 0.904187+0.33054im 0.545873+0.438978im 0.712625+0.785231im 0.281017+0.428674im

julia> rand(ComplexF64, 2) # Less compact
2-element Vector{ComplexF64}:
 0.28745077927138274 + 0.9626892790343715im
  0.7954924735065929 + 0.5122839212553927im

julia> rand(Bool, 2, 10) # Great this is compact
2×10 Matrix{Bool}:
 0 1 0 1 1 0 0 0 1 1
 1 1 0 1 1 1 1 0 0 1

julia> rand(Bool, 2) # Here there is space to be more verbose?
2-element Vector{Bool}:
 1
 1

```

---

<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:** [December 17, 2020, 9:24am UTC](https://discourse.julialang.org/t/what-are-common-mistakes-in-julia-that-beginners-should-aware-of/51874/55 "2020-12-17T09:24:30Z")

</div>

The fact that `Bool <: Integer` leads to a bigger problem that you have to be very careful when implementing indexing and it gets done inconsistently even in Julia Base:

```julia
julia> (1,2,3)[true]
1

julia> [1,2,3][true]
ERROR: ArgumentError: invalid index: true of type Bool

julia> (a=1,b=2,c=3)[true]
ERROR: MethodError: no method matching getindex(::NamedTuple{(:a, :b, :c),Tuple{Int64,Int64,Int64}}, ::Bool)

julia> (1:3)[true]
1

julia> 1[true]
1

```

---

<div class="post-metadata">

**Author:** ![carstenbauer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/carstenbauer/32/4981_2.png) [@carstenbauer](https://discourse.julialang.org/u/carstenbauer)\
**Post date:** [December 17, 2020, 9:48am UTC](https://discourse.julialang.org/t/what-are-common-mistakes-in-julia-that-beginners-should-aware-of/51874/56 "2020-12-17T09:48:32Z")

</div>

That’s a good point and should be considered (might have been?). Personally, I still prefer the `1,0` representation for (long) vectors, though.

---

<div class="post-metadata">

**Author:** ![dmolina](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dmolina/32/5246_2.png) [@dmolina](https://discourse.julialang.org/u/dmolina)\
**Post date:** [December 17, 2020, 12:44pm UTC](https://discourse.julialang.org/t/what-are-common-mistakes-in-julia-that-beginners-should-aware-of/51874/57 "2020-12-17T12:44:14Z")

</div>

Good list. While I know different programming languages, I initially started using Julia as I program in Python, and I find the majority of them. In particular, I spend months without realising that many of my functions returned values even when I did not use _return_, it was very confusing for me 🙄.

---

<div class="post-metadata">

**Author:** ![dmolina](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dmolina/32/5246_2.png) [@dmolina](https://discourse.julialang.org/u/dmolina)\
**Post date:** [December 17, 2020, 1:42pm UTC](https://discourse.julialang.org/t/what-are-common-mistakes-in-julia-that-beginners-should-aware-of/51874/58 "2020-12-17T13:42:39Z")

</div>

In my opinion about the comments in this thread, Julia _conceptually_ is not a complex language. The performance searched implies to be more knowledge about types, it is normal. However, in comparison C++ is a lot more complex (I teach it, and it has many details). My daily small programs in Julia are not more complex than Python (and sometimes is more elegant, using broadcast). About the functional approeach considering the OO in Python is not too strange in my opinion (anyway, in methods the self parameter appear always as the first one), it is a small change, in my opinion.

---

<div class="post-metadata">

**Author:** ![stla](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stla/32/20382_2.png) [@stla](https://discourse.julialang.org/u/stla)\
**Post date:** [January 6, 2021, 10:01am UTC](https://discourse.julialang.org/t/what-are-common-mistakes-in-julia-that-beginners-should-aware-of/51874/59 "2021-01-06T10:01:10Z")

</div>

One mistake I often did is to assign an array `a` to a new variable `b` and modify `b`:

```julia
a = [1, 2]
b = a
b[1] = 9

```

This modifies `a` as well. One has to use copy: `b = copy(a)`. I have a long experience with R and there’s no such a trap in R.

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [January 6, 2021, 12:54pm UTC](https://discourse.julialang.org/t/what-are-common-mistakes-in-julia-that-beginners-should-aware-of/51874/60 "2021-01-06T12:54:08Z")

</div>

@bkamins, very puzzling, why does this happen? I.e., why `true` is not interpreted as an integer in some cases? If we write `Int(true)` (or Int(boolean) more generally) this should get us off the hook.

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

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