# A macro to inspect global variables used in a function?

**URL:** <https://discourse.julialang.org/t/a-macro-to-inspect-global-variables-used-in-a-function/119119>\
**Category:** General Usage\
**Created:** [September 6, 2024, 11:50am UTC](https://discourse.julialang.org/t/a-macro-to-inspect-global-variables-used-in-a-function/119119 "2024-09-06T11:50:39Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![alfaromartino](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alfaromartino/32/52986_2.png) [@alfaromartino](https://discourse.julialang.org/u/alfaromartino)\
**Post date:** [September 6, 2024, 8:13pm UTC](https://discourse.julialang.org/t/a-macro-to-inspect-global-variables-used-in-a-function/119119/3 "2024-09-06T20:13:10Z")

</div>

Note that `@code_warntype` will show any type instability in red. This implies that if you have included any global variable, the result will include some red line.

In case your question is more general about forgetting to add variables, it’s probably a symptom that you have long functions. This means that if you have long functions, it’s probably better if you split them into smaller functions.  
Overall, it’s always recommend to have self contained functions. As for parameters, you can handle them by having a tuple of them that you unpack in the first line of the function. Alternatively, you could define the parameters globally as `const` if you know they won’t change their value.

edit: maybe this [package](https://discourse.julialang.org/t/ann-dispatchdoctor-jl-offers-you-a-prescription-for-type-stability/114837) that forces you to write stable functions can be helpful?

---

_[View the full topic](https://discourse.julialang.org/t/a-macro-to-inspect-global-variables-used-in-a-function/119119)._
