# Environment variables, debugging, globals, etcetera

**URL:** <https://discourse.julialang.org/t/environment-variables-debugging-globals-etcetera/124928>\
**Category:** General Usage\
**Tags:** debugging, environment-variable\
**Created:** [January 19, 2025, 6:59pm UTC](https://discourse.julialang.org/t/environment-variables-debugging-globals-etcetera/124928 "2025-01-19T18:59:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joris\_Pinkse](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joris_pinkse/32/216398_2.png) [@Joris\_Pinkse](https://discourse.julialang.org/u/Joris_Pinkse)\
**Post date:** [January 19, 2025, 6:59pm UTC](https://discourse.julialang.org/t/environment-variables-debugging-globals-etcetera/124928/1 "2025-01-19T18:59:25Z")

</div>

Suppose that I want to use a global switch to turn certain activity on or off. An example activity would be to save a large amount of state information to disk after an iteration (or not).

There are several ways of achieving this, including passing a flag. Another would be to read the status of the environment variable `JULIA_DEBUG` or to use my own environment variable, say `FOO_BAR`.

What are the pros and cons of using `FOO_BAR` here? Again, I’m thinking of the case in which it is set once in the calling code and not touched again on a run (but whose value is not precompiled).

Alternative suggestions?

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [January 19, 2025, 11:10pm UTC](https://discourse.julialang.org/t/environment-variables-debugging-globals-etcetera/124928/2 "2025-01-19T23:10:09Z")

</div>

> [@Joris\_Pinkse](#):
>
> Alternative suggestions?

If possible, I would try to avoid global configuration variables if possible. e.g. create a “configuration object” that has all of your settings, and pass that around as a parameter to your functions.

Using global state can lead to a long-term headaches — it makes the code harder to compose, e.g. imagine two different packages want to use your code in different ways in the same program.

---

<div class="post-metadata">

**Author:** ![Joris\_Pinkse](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joris_pinkse/32/216398_2.png) [@Joris\_Pinkse](https://discourse.julialang.org/u/Joris_Pinkse)\
**Post date:** [January 19, 2025, 11:49pm UTC](https://discourse.julialang.org/t/environment-variables-debugging-globals-etcetera/124928/3 "2025-01-19T23:49:12Z")

</div>

Thanks @stevengj . Yes, that’s what I’ve been doing for most such things. I’d failed to mention that this is something for me to turn on/off while testing, not a user option.

Perhaps [@assert alternatives? - #14 by WschW](https://discourse.julialang.org/t/assert-alternatives/24775/14) could work
