# Overriding exported variables in Main after using, bad idea?

**URL:** <https://discourse.julialang.org/t/overriding-exported-variables-in-main-after-using-bad-idea/2875>\
**Category:** General Usage\
**Created:** [March 25, 2017, 3:24pm UTC](https://discourse.julialang.org/t/overriding-exported-variables-in-main-after-using-bad-idea/2875 "2017-03-25T15:24:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jonathanBieler](https://avatars.discourse-cdn.com/v4/letter/j/82dd89/32.png) [@jonathanBieler](https://discourse.julialang.org/u/jonathanBieler)\
**Post date:** [March 25, 2017, 3:24pm UTC](https://discourse.julialang.org/t/overriding-exported-variables-in-main-after-using-bad-idea/2875/1 "2017-03-25T15:24:26Z")

</div>

Is there something particularly wrong about doing something like that:

```julia
module Module1
    export A,B,f,g
    ...
end

using Module1
A = Module1.A
B = Module1.B
f = Module1.f
g = Module1.g

```

I have a macro that does that automatically and that would allow not to have to qualify every use of Module1’s fields when working on a module.

---

<div class="post-metadata">

**Author:** ![ohsonice](https://avatars.discourse-cdn.com/v4/letter/o/d6d6ee/32.png) [@ohsonice](https://discourse.julialang.org/u/ohsonice)\
**Post date:** [March 25, 2017, 5:11pm UTC](https://discourse.julialang.org/t/overriding-exported-variables-in-main-after-using-bad-idea/2875/2 "2017-03-25T17:11:22Z")

</div>

In your example it is not actually necessary to redefine variables like that, unless you want to change the name of the variables. Check out this documentation (specifically the first table that talks about what is brought into scope by using different commands: [http://docs.julialang.org/en/stable/manual/modules/](http://docs.julialang.org/en/stable/manual/modules/)

I’m not knowledgable enough to tell you if what you’re doing is bad practice or not but see below example:

> julia\> module MyModule  
> export A  
> A(s) = s +1  
> end  
> MyModule

> julia\> using MyModule

> julia\> A(1)  
> 2

---

<div class="post-metadata">

**Author:** ![jonathanBieler](https://avatars.discourse-cdn.com/v4/letter/j/82dd89/32.png) [@jonathanBieler](https://discourse.julialang.org/u/jonathanBieler)\
**Post date:** [March 25, 2017, 5:18pm UTC](https://discourse.julialang.org/t/overriding-exported-variables-in-main-after-using-bad-idea/2875/3 "2017-03-25T17:18:39Z")

</div>

Yes, I’m talking about modifying MyModule, in which case you either have to use workspace() each time or MyModule.A(1) everywhere.

---

<div class="post-metadata">

**Author:** ![Ralph\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ralph_smith/32/10344_2.png) [@Ralph\_Smith](https://discourse.julialang.org/u/Ralph_Smith)\
**Post date:** [March 25, 2017, 6:18pm UTC](https://discourse.julialang.org/t/overriding-exported-variables-in-main-after-using-bad-idea/2875/4 "2017-03-25T18:18:03Z")

</div>

If you have other entities in Main that refer to things in the old Module1, there may be confusion.

Do you really want to keep so much in Main? [The manual (workflow tips)](http://docs.julialang.org/en/stable/manual/workflow-tips/) suggests putting your testing code in its own module, e.g.

```julia
module M1Tester
using Module1

# code that involves unqualified references to Module1 exports
end

```

Then a fruitful workflow is

```julia
julia> include("module1.jl"); include("m1tester.jl")
[edit and save]
julia> include("module1.jl"); include("m1tester.jl")
[repeat]

```

(or `reload` for a package). The new instance of the tester sees only the latest Module1. The manual talks of restarting the REPL here, but in most cases that is unnecessary.

---

<div class="post-metadata">

**Author:** ![jonathanBieler](https://avatars.discourse-cdn.com/v4/letter/j/82dd89/32.png) [@jonathanBieler](https://discourse.julialang.org/u/jonathanBieler)\
**Post date:** [March 26, 2017, 12:11pm UTC](https://discourse.julialang.org/t/overriding-exported-variables-in-main-after-using-bad-idea/2875/5 "2017-03-26T12:11:56Z")

</div>

My understanding is that one reason why you have to bother with this module business in the first place is that you can’t reload cleanly your module into Main. I’ve done some testing and my method seems to work fine, I guess I’ll try to work with it for a while and see how it goes.
