Search code examples
oopsyntaxjuliaperceptronparadigms

Alternative to OOP in Julia


I'm trying to learn a bit of Julia, so i'm writing some small projects in the language.

I'd like to write, for example, a simple Perceptron in Julia, but it is not object oriented, so i can't create a class Perceptron, like in python

What is a possible alternative to write a code like in Python? I saw that there are structures, but this looks like C structure, so I was wondering if there is a more powerful way.


Solution

  • The "more powerful way" you're seeking is the type hierarchy system: https://docs.julialang.org/en/v1/manual/types/

    In julia, despite not being OOP, you can still subtypes other types with <: when making its definition (but the supertype must be an abstract type, there are subtypes of parametrized type too, but they aren't made with <:)

    The subtypes keep the method specialisation of their parents, unless you change their definition.

    One of the effect of Julia subtyping on abstract types is that childs don't inherit of parents fields (as they just don't have one).