# Custom versus Package function names

**URL:** <https://discourse.julialang.org/t/custom-versus-package-function-names/48711>\
**Category:** New to Julia\
**Created:** [October 20, 2020, 10:06pm UTC](https://discourse.julialang.org/t/custom-versus-package-function-names/48711 "2020-10-20T22:06:10Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![dalarev](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dalarev/32/9881_2.png) [@dalarev](https://discourse.julialang.org/u/dalarev)\
**Post date:** [October 20, 2020, 10:06pm UTC](https://discourse.julialang.org/t/custom-versus-package-function-names/48711/1 "2020-10-20T22:06:10Z")

</div>

I think I am having issues with my custom function `grid` conflicting with the Plots package `grid` .

How can I specify (is “qualify” the better term?) that I want to use my own? To specify Plots’ version, I would do Plots.grid.

I’m having a strange issue where my resulting data changes when I generate a pyplot heatmap - if I comment out the heatmap line, results are correct and consistent after several executions; if I activate it again, results change after every few executions. I checked that this doesn’t happen with GR heatmap. I’ve tried but have not worked out a MWE, so I won’t go too in-depth here.

One solution could be to only import the heatmap function from the Plots package. What would be the syntax if I want the GR heatmap? `using Plots.gr.heatmap` ?

Another option would be to simply rename my function. Hoping to find a more elegant solution.

---

<div class="post-metadata">

**Author:** ![cojua8](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cojua8/32/11882_2.png) [@cojua8](https://discourse.julialang.org/u/cojua8)\
**Post date:** [October 20, 2020, 10:20pm UTC](https://discourse.julialang.org/t/custom-versus-package-function-names/48711/2 "2020-10-20T22:20:56Z")

</div>

when you have conflicting names of functions, you must use qualifiers:

`Package1.function_name`  
`Package2.function_name`

---

<div class="post-metadata">

**Author:** ![tbeason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tbeason/32/15898_2.png) [@tbeason](https://discourse.julialang.org/u/tbeason)\
**Post date:** [October 20, 2020, 10:29pm UTC](https://discourse.julialang.org/t/custom-versus-package-function-names/48711/3 "2020-10-20T22:29:54Z")

</div>

If you just use `import Plots` then you will be forced to prepend all calls to Plots.jl functions with `Plot.` and I think that will resolve the conflict at the expense of some extra verbosity on your plotting calls.

---

<div class="post-metadata">

**Author:** ![dalarev](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dalarev/32/9881_2.png) [@dalarev](https://discourse.julialang.org/u/dalarev)\
**Post date:** [October 20, 2020, 10:46pm UTC](https://discourse.julialang.org/t/custom-versus-package-function-names/48711/4 "2020-10-20T22:46:08Z")

</div>

This may be the right call. Does `import` differ from `using` in that you now must prepend all calls to Plots functions with Plot?

Since we’re here…what would be the correct syntax for specifying a backend? `Plots.gr.heatmap`?

---

<div class="post-metadata">

**Author:** ![cojua8](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cojua8/32/11882_2.png) [@cojua8](https://discourse.julialang.org/u/cojua8)\
**Post date:** [October 21, 2020, 2:07pm UTC](https://discourse.julialang.org/t/custom-versus-package-function-names/48711/5 "2020-10-21T14:07:50Z")

</div>

I think you just set the backend, and then if you use `heatmap`, the Plots package will know it has to use the heatmap from GR backend

Look here: [http://docs.juliaplots.org/latest/generated/gr/#gr-examples](http://docs.juliaplots.org/latest/generated/gr/#gr-examples)

---

<div class="post-metadata">

**Author:** ![dalarev](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dalarev/32/9881_2.png) [@dalarev](https://discourse.julialang.org/u/dalarev)\
**Post date:** [October 21, 2020, 8:26pm UTC](https://discourse.julialang.org/t/custom-versus-package-function-names/48711/6 "2020-10-21T20:26:03Z")

</div>

Right, but what if I want to use a qualifier for my own function? What is the syntax then?

---

<div class="post-metadata">

**Author:** ![dalarev](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dalarev/32/9881_2.png) [@dalarev](https://discourse.julialang.org/u/dalarev)\
**Post date:** [October 21, 2020, 8:39pm UTC](https://discourse.julialang.org/t/custom-versus-package-function-names/48711/7 "2020-10-21T20:39:26Z")

</div>

This seems to be the best solution for me for exactly the reasons you note. Appreciate the help!

---

<div class="post-metadata">

**Author:** ![roble](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/roble/32/12303_2.png) [@roble](https://discourse.julialang.org/u/roble)\
**Post date:** [October 21, 2020, 10:26pm UTC](https://discourse.julialang.org/t/custom-versus-package-function-names/48711/8 "2020-10-21T22:26:06Z")

</div>

Instead of always having to write `Package. ` you can create a constant eg. `const P = Package`. From now on you can use `P. ` instead of `Package. ` if that is too verbose for you.

---

<div class="post-metadata">

**Author:** ![briochemc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/briochemc/32/4209_2.png) [@briochemc](https://discourse.julialang.org/u/briochemc)\
**Post date:** [October 22, 2020, 1:13am UTC](https://discourse.julialang.org/t/custom-versus-package-function-names/48711/9 "2020-10-22T01:13:08Z")

</div>

> [@dalarev](#):
>
> This may be the right call. Does `import` differ from `using` in that you now must prepend all calls to Plots functions with Plot?

Yes, but not only. With `import`, you can now redefine and add methods to functions of the package. For example, I could do

```julia
julia> import Plots

julia> Plots.heatmap(x::String) = "This is not a plot"

julia> Plots.heatmap("foo")
"This is not a plot"

julia> Plots.heatmap(x,y,z) = "Broke this one too"

julia> Plots.heatmap(1:10, 1:10, rand(10,10))
"Broke this one too"

```

* * *

> [@dalarev](#):
>
> Since we’re here…what would be the correct syntax for specifying a backend? `Plots.gr.heatmap` ?

I _think_ the correct way is more

```julia
julia> using Plots

julia> gr()
Plots.GRBackend()

```

---

<div class="post-metadata">

**Author:** ![dalarev](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dalarev/32/9881_2.png) [@dalarev](https://discourse.julialang.org/u/dalarev)\
**Post date:** [October 22, 2020, 2:26pm UTC](https://discourse.julialang.org/t/custom-versus-package-function-names/48711/10 "2020-10-22T14:26:28Z")

</div>

Yes, when importing Plots the syntax is:

`import Plots; Plots.gr()` or `Plots.pyplot()`

and to check which backend is being used, `Plots.backend()`

Appreciate the info!
