Julia: OOP or not

When in doubt, read the documentation...

https://docs.julialang.org/en/v1/manual/types/#Composite-Types-1

Long story short:

struct MyType
    a::Int64
    b::Float64
end

x = MyType(3, 4)

x.a

EDIT: Methods are defined outside the type definition, e.g.

function double(x::MyType)
    x.a *= 2
end

Methods do not live inside the type, as they would do in C++ or Python, for example. This allows one of the key features of Julia, multiple dispatch, to work also with user-defined types, which are on exactly the same level as system-defined types.


Julia is not object-oriented in the full sense because you cannot attach methods to Julia's objects ("types"). The types do seem very similar to objects though. However, since they do not have their own associated methods and there is no inheritance the objects themselves don't do the acting. Instead you have functions which act on the objects.

The difference is ball.checkCollision() vs checkCollision(ball,Walls). In reality it's not that big of a deal. You can make something like inheritance by having a type have a field of another type, and multiple dispatch lets you write functions which do different things based on the objects you give them, which can be almost like object methods. The real difference is where you save the function and types in a file. So you can do a kind of quasi-objected-oriented style in Julia, but it's still distinctly different than OOP languages.


The answer is that Julia is closer to c rather than c++. Thus, OOP is limited in Julia having only c::struct rather than c++::class. Hence, it's just data encapsulation or data structure or customization of Types rather than true OOP objects, in the strict sense.


I would like to mention this worthfull conversation within Julia users group Julia and Object-Oriented Programming.
For me Julia is not like a conventional OO language, and I always like to think of Julia, as more a Method Oriented language that an Object Oriented one, that is because if you try to create an structure of encapsulated data and functionality in Julia, soon you will get yourself into trouble.