Have a read through http://docs.julialang.org/en/release-0.3/manual/performance-tips/
Basically, the fields should have a concrete type if used in performance critical code. Otherwise, no annotations are fine. Note that there is not performance gain from annotating with non-concrete types (like Integer, Array). On Thu, 2015-05-07 at 05:50, Alexandros Fakos <[email protected]> wrote: > Hi, > > Reading the Julia style guide I see "avoid writing overly-specific types > <http://julia.readthedocs.org/en/latest/manual/style-guide/#avoid-writing-overly-specific-types> > " > > *The main reason I use composite types is in order to aggregate variables > and avoid variable name conflicts (the same reason I use structures in > Matlab)*. > > So when I define a data type, I usually define the fieldtypes as* Any or > Array* or *Number* or *Integer * > > *Questions* > > *1)* Is there any reason to define fieldtypes instead leaving fields with > no type annotation? > > *2) *How much performance do I sacrifice by defining a field as *Any* instead > of *Array *or instead of Array{Float64,2} or Array{Number,2}? > > *3)* suppose I define: > > type Mytype > a:: Array{Number,1} > b:: Array > c > end > > then I create an object by > > *var=Mytype( [1;2] , [1;2], [1;2] )* > > julia> typeof(var.a) > Array{Number,1} > > julia> typeof(var.b) > Array{Int64,1} > > julia> typeof(var.c) > Array{Int64,1} > > > Why field a is Array{Number,1} while b and c is Array{Int64,1} ? Isn't > Number generic enough to be turned into Int64? > > Thanks a lot, > Alex
