# How different are the ways of aliasing functions?

**URL:** https://discourse.julialang.org/t/how-different-are-the-ways-of-aliasing-functions/15824
**Category:** General Usage
**Created:** [October 3, 2018, 11:22am UTC](https://discourse.julialang.org/t/how-different-are-the-ways-of-aliasing-functions/15824 "2018-10-03T11:22:46Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![LeoK987](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/leok987/32/4880_2.png) [@LeoK987](https://discourse.julialang.org/u/LeoK987)
#### Post date: [October 3, 2018, 11:22am UTC](https://discourse.julialang.org/t/how-different-are-the-ways-of-aliasing-functions/15824/1 "2018-10-03T11:22:46Z")

</div>

Say I have 2 functions:

```julia
function f1(i::Int)
    i
end

function f2(i::Int)
    2*i
end

```

I have these 2 ways of aliasing them:

```julia
f = f1
g(i::Int) = f1(i)

```

Calling either f or g give the right result, but somehow, calling f results in more memory allocation. Why is that?

---

<div class="post-metadata">

### Author: ![foobar\_lv2](https://avatars.discourse-cdn.com/v4/letter/f/ee59a6/32.png) [@foobar\_lv2](https://discourse.julialang.org/u/foobar_lv2)
#### Post date: [October 3, 2018, 11:29am UTC](https://discourse.julialang.org/t/how-different-are-the-ways-of-aliasing-functions/15824/2 "2018-10-03T11:29:14Z")

</div>

`f` is a global scope variable that can change during the lifetime of your program. Julia has to compile code that does not become invalid if you later set `f=0`.

You can later on add/redefine methods for the function `f1` and julia is capable of tracking which compiled methods need to be invalidated / recompiled. Julia is not willing to track the same for global non-constant variables.

TLDR: `const f=f1`
