# Older versions of custom functions are saved as methods

**URL:** <https://discourse.julialang.org/t/older-versions-of-custom-functions-are-saved-as-methods/89935>\
**Category:** New to Julia\
**Created:** [November 8, 2022, 2:47pm UTC](https://discourse.julialang.org/t/older-versions-of-custom-functions-are-saved-as-methods/89935 "2022-11-08T14:47:11Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mylo19](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mylo19/32/43957_2.png) [@mylo19](https://discourse.julialang.org/u/mylo19)\
**Post date:** [November 8, 2022, 2:47pm UTC](https://discourse.julialang.org/t/older-versions-of-custom-functions-are-saved-as-methods/89935/1 "2022-11-08T14:47:11Z")

</div>

This may be simple, but as I’m now getting used to multiple dispatch, I want to be sure that I understand how to work properly.

I’m writing some custom functions for my project.

Let’s say I have the following function:

```julia
function myFun(arg1, arg2)
    return arg1+arg2
end

```

I run the code, and then realise that for my purposes, `myFun` should have three arguments instead of two. So I redefine `myFun` as:

```julia
function myFun(arg1, arg2, arg3)
    return arg1+arg2+arg3
end

```

When I run the code, I see that `myFun` now has two methods. Running `methods(myFun)`, I see that the older version of `myFun` still exists as a method.

It’s not that I want to keep both, as two methods. The older version was incorrect for what I wanted to do and can possibly lead to some bugs, if it’s called instead of the updated version.

How do you deal with this? Do you delete the older methods? If yes, doing something like [that](https://discourse.julialang.org/t/deleting-methods-in-julia/13455)? Is there an alternative, where the updated function deletes the older version?

---

<div class="post-metadata">

**Author:** ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)\
**Post date:** [November 8, 2022, 2:56pm UTC](https://discourse.julialang.org/t/older-versions-of-custom-functions-are-saved-as-methods/89935/2 "2022-11-08T14:56:24Z")

</div>

Since the two methods take a different number of arguments, there is no way for julia to know that you intend to use one over the other. I’m guessing you’re just defining both in the REPL?

For functions in files, Revise.jl can take care of deletion for you, I think.

---

<div class="post-metadata">

**Author:** ![mylo19](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mylo19/32/43957_2.png) [@mylo19](https://discourse.julialang.org/u/mylo19)\
**Post date:** [November 8, 2022, 3:16pm UTC](https://discourse.julialang.org/t/older-versions-of-custom-functions-are-saved-as-methods/89935/3 "2022-11-08T15:16:49Z")

</div>

I’m defining them in a file, that’s why I’m having this question/issue.

So I’m just changing my file, and then running it again. I think it would be really helpful if julia could understand that I changed the function in the file, and the old one doesn’t exist.

I will check the package you mentioned, thanks!

---

<div class="post-metadata">

**Author:** ![mikmoore](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mikmoore/32/31109_2.png) [@mikmoore](https://discourse.julialang.org/u/mikmoore)\
**Post date:** [November 8, 2022, 3:43pm UTC](https://discourse.julialang.org/t/older-versions-of-custom-functions-are-saved-as-methods/89935/4 "2022-11-08T15:43:16Z")

</div>

If they are in a module, `Revise` can track them. If they’re in a file you’re `include`-ing into the REPL, you can use `includet` (include-and-track) from `Revise` and I believe that will still work.

I don’t remember the exact details, but I believe I’ve had the cleanest experience if the file I’m `includet`-ing has only function definitions and then I call those from the REPL (rather than containing functions and a test script). For example, create a `main()` function in the file that you then call from the REPL to run your test.

It _may_ also work to repeatedly `includet` the file, although I recall that any script-like parts may not be re-run on subsequent `indludet`s. You could try to `include` after `includet` to re-run but that may or may not cause issues with updating the methods.

---

<div class="post-metadata">

**Author:** ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)\
**Post date:** [November 8, 2022, 3:43pm UTC](https://discourse.julialang.org/t/older-versions-of-custom-functions-are-saved-as-methods/89935/5 "2022-11-08T15:43:45Z")

</div>

> [@mylo19](#):
>
> So I’m just changing my file, and then running it again. I think it would be really helpful if julia could understand that I changed the function in the file, and the old one doesn’t exist.

How are you running the file again? Restarting julia should already clear the old state.

If you’re running it from e.g. VSCode, Revise.jl will definitely help you out - I think the julia extension also already has support for that.

---

<div class="post-metadata">

**Author:** ![mylo19](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mylo19/32/43957_2.png) [@mylo19](https://discourse.julialang.org/u/mylo19)\
**Post date:** [November 10, 2022, 10:02am UTC](https://discourse.julialang.org/t/older-versions-of-custom-functions-are-saved-as-methods/89935/6 "2022-11-10T10:02:29Z")

</div>

I’m running it from VS Code.

Will definitely check `Revise` .

Thank you both very much for your answers!

---

<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:** [November 10, 2022, 10:57am UTC](https://discourse.julialang.org/t/older-versions-of-custom-functions-are-saved-as-methods/89935/7 "2022-11-10T10:57:13Z")

</div>

I think Revise is loaded by default in VSCode. Then I think you just need to use `includet(file.jl)`, instead of `include` (note the extra `t` - for track).

Then, you don’t need to `includet` repeatedly, just modify the file and run your function again.
