I come from a Python background where direct access to fields in for 
example classes with the dot notation is very common.

However, from what I have seen in different conversations, accessing fields 
directly is not really Julian. Sort of a "fields are an implementation 
detail" mindset, and "what is important are the functions".

Here is an example of a type hierarchy that is a little bit similar to 
types I am working with now:

type Element
    vertices::Vector{Int}
end

type Node
    coordinates::Vector{Float64}
    id::Int
end

type FESection
    elements::Vector{Elements}
    nodes::Vector{Nodes}
end

type Mesh
   sections::Vector{FESection}
end

Now, let's say that I want to write a function to loop over all vertices. 
One way (which I would do in Python is):

mesh = Mesh(.....)
for section in mesh.sections
    for element in section.elements
        for vertices in element.vertices
              blah bla
        end
    end
end



However, this accesses the fields directly. Would it be more Julian to 
write getters for the fields? Since Julia does not have @property like 
Python I realize that by accessing the fields you commit to exactly the 
name of the field and it's type while with a getter it would be more 
flexible.

Best regards,
Kristoffer Carlsson

Reply via email to