How to correctly define and use global variables in the module in Julia?

I’d like to add that in the vast majority of cases, restructuring the program to use no globals at all and instead passing arguments around explicitly can lead to increases in performance. If the compiler doesn’t have to insert expensive global lookups (because it’s all on the stack of a function), your code is much more likely to be fast (and race free, in case of multithreaded code, which has become much more common in regular julia code since 1.3).

4 Likes