# Passing 'global' functions

**URL:** <https://discourse.julialang.org/t/passing-global-functions/57140>\
**Category:** New to Julia\
**Created:** [March 14, 2021, 5:34pm UTC](https://discourse.julialang.org/t/passing-global-functions/57140 "2021-03-14T17:34:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jovansam](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jovansam/32/15023_2.png) [@jovansam](https://discourse.julialang.org/u/jovansam)\
**Post date:** [March 14, 2021, 5:34pm UTC](https://discourse.julialang.org/t/passing-global-functions/57140/1 "2021-03-14T17:34:16Z")

</div>

It is [recommended to pass global variables to functions](https://docs.julialang.org/en/v1/manual/performance-tips/#Measure-performance-with-%5B@time%5D(@ref)-and-pay-attention-to-memory-allocation). What I wonder is whether it is good practice to pass functions as well. These functions can be declared in global scope or in outer (relative to an inner) scope. I have seen some code where functions are passed but this does not appear to be really necessary for the program to run correctly.

---

<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:** [March 14, 2021, 9:38pm UTC](https://discourse.julialang.org/t/passing-global-functions/57140/2 "2021-03-14T21:38:49Z")

</div>

Functions declared in global scope are constants, equivalent to `const` global variables, so it is not necessary to pass them as function arguments for good performance.

(It doesn’t hurt to pass functions as arguments, on the other hand, and [higher-order functions](https://en.wikipedia.org/wiki/Higher-order_function) are fast in Julia.)

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [March 14, 2021, 10:27pm UTC](https://discourse.julialang.org/t/passing-global-functions/57140/3 "2021-03-14T22:27:29Z")

</div>

Just be careful to not use a non-constant global variable bound to a function, like

```julia
julia> f = sin

```

or

```julia
julia> g = x -> 2x

```

This is sometime source of confusion. f and g here are not constants and cause type instabilities.
