# Functions with independent (global) scopes

**URL:** https://discourse.julialang.org/t/functions-with-independent-global-scopes/103703
**Category:** General Usage
**Created:** [September 9, 2023, 2:51pm UTC](https://discourse.julialang.org/t/functions-with-independent-global-scopes/103703 "2023-09-09T14:51:39Z")
**Posts on this page:** 1
**Showing post:** 8

<div class="post-metadata">

### Author: ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)
#### Post date: [September 9, 2023, 11:25pm UTC](https://discourse.julialang.org/t/functions-with-independent-global-scopes/103703/8 "2023-09-09T23:25:46Z")

</div>

You can spot global variables in functions with reflection, even something as simple as:

```julia
julia> foo() = sin(x) # oops I forgot to write `foo(x)`
foo (generic function with 1 method)

julia> @code_warntype foo()
MethodInstance for foo()
  from foo() in Main at REPL[12]:1
Arguments
  #self#::Core.Const(foo)
Body::Any
1 ─ %1 = Main.sin(Main.x)::Any
└── return %1

```

But you need to distinguish the intended globals like `Main.sin` or the unintended globals like `Main.x`. You don’t have to do this much work if you get the habit of writing all the necessary arguments into a function header, it’s a good habit in any language.

---

_[View the full topic](https://discourse.julialang.org/t/functions-with-independent-global-scopes/103703)._
