Concrete Example 0805: how to prevent using global variable in the module?

It will be much better if you initialize mussigma inside the init function and return it to the user.
Then pass mussigma to the next function that will use it as a parameter.

Something like:

module Mixture

  export init, compute

  function init(...)
     mussigma = Vector{...}(undef,...)
     ...
     return mussigma
  end

  function compute(mussigma)
    ...
    return result
  end

end

using Mixture

mussigma = init(...)

result = compute(mussigma)


Try to forget completely about the possibility of using global variables, that is the best advice.

3 Likes