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

**URL:** <https://discourse.julialang.org/t/how-to-correctly-define-and-use-global-variables-in-the-module-in-julia/65720>\
**Category:** General Usage\
**Created:** [August 3, 2021, 5:46am UTC](https://discourse.julialang.org/t/how-to-correctly-define-and-use-global-variables-in-the-module-in-julia/65720 "2021-08-03T05:46:29Z")\
**Posts on this page:** 1\
**Showing post:** 18

<div class="post-metadata">

**Author:** ![genkuroki](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/genkuroki/32/18030_2.png) [@genkuroki](https://discourse.julialang.org/u/genkuroki)\
**Post date:** [August 5, 2021, 11:21pm UTC](https://discourse.julialang.org/t/how-to-correctly-define-and-use-global-variables-in-the-module-in-julia/65720/18 "2021-08-05T23:21:38Z")

</div>

Don’t use global variables in the function without passing them as arguments.

In my personal opinion, it is also better to avoid using global constants, especially when using Julia for scientific research. Using constants to fix the types inhibits unpredictable composability with various packages.

For example, if you want to see what happens when you perturb the fundamental constant `a`, and if you fix the type of `a` with `const a = ~`, then you will not be able to apply packages such as [MonteCarloMeasurements.jl](https://github.com/baggepinnen/MonteCarloMeasurements.jl) to `a`.

Every time you use a constant to fix the type, you are inhibiting yourself from coming up with scientific ideas on how to use Julia.

---

_[View the full topic](https://discourse.julialang.org/t/how-to-correctly-define-and-use-global-variables-in-the-module-in-julia/65720)._
