In some cases a composite type may allow you to organize your code better. For example, I would usually prefer
type BodyMetrics weight::Float64 height::Float64 waist::Float64 end to a Vector[3] because I would be concerned that I would mix up the order of fields without explicitly specifying them. With a composite type, Julia would take care of that for me. However, if you are just modeling points with 3d coordinates then a Vector[3] may be a more natural choice, because you already have the basic linear operators (+, .*, ...) defined. So you should think about the problem and choose the representation that feels more natural. HTH, Tamas On Tue, Mar 03 2015, Chris <[email protected]> wrote: > Hello, > > Most of my Julia code basically involves dynamics simulations, and thus > state vectors. So far, I have simply been using ::Vector{Float64} as the > type for my state vectors, but I have seen other Julia code that defines a > composite type for this, something like: > > type StateVec > x::Float64 > y::Float64 > z::Float64 > end > > My question is (hopefully) simple: what benefit, if any, does this give > over simply using Vector{Float64}? If it is not quite obvious by now, I am > a Matlab transplant, and this is one of those things I haven't quite been > able to wrap my head around yet. > > Thanks, > Chris
