Hi Michael
As Stefan just pointed out, in Julia one should in general take advantage
of the Multiple Dispatch paradigm and write functions that dispatch on the
types instead of having functions belonging to the type (as you would have
in Python).
Let me give you a simple example by rewriting you Fyle type.
You have something like this
type Fyle
size::Float64
origSize::Float64
lifetime::Int
get_lifetime::Function
get_size::Function
function Fyle(size = 0)
this = new()
this.size=size
this.lifetime=0
this.origSize=size
this.get_lifetime = function()
return(this.lifetime)
end
this.get_size = function()
return(this.size)
end
return this
end
end
when you should have really written something like this
# I am going to define a method size for you type Fyle
# size is a generic function in Base, so one should import it on order to
be able to extend it for a user Type
import Base.size
type Fyle
size::Float64
origSize::Float64
lifetime::Int
end
# Outer constructor (in some cases you might want to define an inner one as
you did)
# Read the manual section on Constructors
Fyle(size=0) = Fyle(size, size, 0)
# Define the desired functions to dispatch on the Type
lifetime(f::Fyle) = f.lifetime
size(f::Fyle) = f.size
Hope this helps.
Greetings, Pablo