15

Let's define 4 different classes of points:

type PointType
    x
    y
end

mutable struct PointMut
    x
    y
end

immutable PointImmut
    x
    y
end

struct PointStruct
    x
    y
end

What is the difference between PointType and PointMut? Why would someone choose one over the other?

Also what is the difference between PointImmut and PointStruct?

I tend to believe that they are just synonyms, but I didn't find this stated explicitly, so I wonder if there is a subtle difference hidden somewhere.

1

1 Answer 1

37

type and immutable are valid up to julia 0.6, mutable struct and struct are the names of the same objects in julia 0.6 and forward. mutablein mutable struct means that the fields can change - which is actually fairly rarely used so being immutable is the default. mutable struct's are slower than structs.

1
  • 1
    that's because it's being deprecated. The fact that type and immutable ever existed will be something for the history books soon. Oct 21, 2017 at 14:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.