On Monday, 26 October 2015 11:17:58 UTC-7, Christoph Ortner wrote: > > Fabian - Many thanks for your comments. This was very helpful. > > (c) if I want to write code now that shouldn't break with 0.5, what should >> I do? >> > > I think when you need a copy, just surround your getindex with a copy > function. (e.g. copy(x[:,10]) instead of x[:,10]). > > But this would lead me to make two copies. I was more interested in seeing > whether there is a guideline on how to write code now so it doesn't have to > be rewritten for 0.5. > > > you could do copy(sub(x, :, 10)) to avoid two copies. Not as pretty ;)
> My own scepticism comes from the idea that using immutable objects > throughout prevents bugs and one should only use mutable objects sparingly > (primarily for performance - but I thought it shouldn't be the default) > > the all immutable idea has its merits, but it is really not how Julia works already. If I pass the name of an array to a function I get a reference not a copy. I only get a copy of a slice of that same array at the moment which feels inconsistent to me. if your function accepts an array and you are mutating it in the body of the function I really don't like that func(a) func(b[1:2, 3:4]) has different behavior if I am mutating the passed in array. This will be a source of far more bugs in my mind than simply having it so that if you mutate the passed in arguments to a function you are changing the parameters. Also I would hate to have to do func(ref(a)) or some such thing when I have no plans to change a in my function (which for me is the farrrrrr more common case). Ultimately I find that Julia treats us like consenting adults when it comes to passing objects to functions ... and the new array views behavior simply adds consistency.