Preallocating arrays is often a good practice, but you can still pass them as arguments — it doesn’t require you to use globals.
In any case, as @ericphanson pointed out above, a statement like B₊ = B * M
or 𝐃₊ = [Hermitian(M'*D*M) for D ∈ 𝐃]
allocates new arrays anyway — you are “rebinding” the variables B₊
and 𝐃₊
to “point” to new arrays in memory, not mutating them in-place. See also this discussion.
(This is not unique to Julia! If you do a = [3,4,5]
, then b = a
, followed by a = [4,5,6]
in Python or Matlab or most other languages with analogous operations, b
will still be [3,4,5]
.)