Copying things by default isn’t a very good strategy for a language used to do linear algebra on large arrays.
Requiring that people use Ref to get reasonable performance for linear algebra operations would make Julia feel like a much more low-level language than it is currenty. — John On Aug 20, 2014, at 5:16 AM, Adam Strzelecki <[email protected]> wrote: > Frankly current Julia semantics is pretty confusing and IMHO inflexible at > least for me as a programmer and scientists at once using C++ everyday. Why > not have by-value as default behavior for types and Ref{...} turns by-val > type to reference type? E.g.: > > type Point > x; y > end > rotate!(p::Ref{Point}) = ... # if we pass variable of type Point it will be > promoted to reference there > rotate(p::Point) = ... # the passed variable is just copied (byval) > > Or for some OO-like classes if we want to have reference type straight ahead > (and we don't want to provide value type) do: > > @ref type Employee > const badge::Int # badge number stays the same (badge field must > initialized once in constructor) > name::String # employee may change her/his name > end > # would be short for: > type EmployeeVal > ... > end > typealias Employee Ref{EmployeeVal} > # except EmployeeVal won't exists when using reftype > > Also Julia could provide isref isval tests for types or variables, this would > be as easy as testing if variable or class is typeof Ref{...}: > > isref(Employee) # => true > isval(Point) # => true > > Also we could make shorthand for declaring all fields const with: > > @const type Pixel > x::Int; y::Int > end > # equivalent for... > type Pixel > const x::Int > const y::Int > end > > I know this is kinda late, as Julia seems to be pretty mature language, > however this won't change lot for existing scripts. > > Also I regret that all Julia isn't making all locals, arguments and fields as > const by default (similar to Apple's Swift), requiring some "var" qualifier, > but this is different story. > > --Adam
