# Unexported functions

**URL:** <https://discourse.julialang.org/t/unexported-functions/28061>\
**Category:** General Usage\
**Tags:** question\
**Created:** [August 27, 2019, 7:14pm UTC](https://discourse.julialang.org/t/unexported-functions/28061 "2019-08-27T19:14:04Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mrkaspa](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mrkaspa/32/7236_2.png) [@mrkaspa](https://discourse.julialang.org/u/mrkaspa)\
**Post date:** [August 27, 2019, 7:14pm UTC](https://discourse.julialang.org/t/unexported-functions/28061/1 "2019-08-27T19:14:05Z")

</div>

Why if I have a module like this:

module Demo

suma(a) = a + 1

end

I can access it through Demo.suma(123), if it has not been exported, should not be exported first to be accessed?

---

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [August 27, 2019, 7:16pm UTC](https://discourse.julialang.org/t/unexported-functions/28061/2 "2019-08-27T19:16:48Z")

</div>

No, `export` only affects what you get when you `using`. You might find [Modules · The Julia Language](https://docs.julialang.org/en/v1/manual/modules/#Summary-of-module-usage-1) useful.

---

<div class="post-metadata">

**Author:** ![mrkaspa](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mrkaspa/32/7236_2.png) [@mrkaspa](https://discourse.julialang.org/u/mrkaspa)\
**Post date:** [August 27, 2019, 7:21pm UTC](https://discourse.julialang.org/t/unexported-functions/28061/3 "2019-08-27T19:21:35Z")

</div>

So there is no way to make something private to the module?

---

<div class="post-metadata">

**Author:** ![tviti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tviti/32/9975_2.png) [@tviti](https://discourse.julialang.org/u/tviti)\
**Post date:** [August 27, 2019, 7:39pm UTC](https://discourse.julialang.org/t/unexported-functions/28061/4 "2019-08-27T19:39:43Z")

</div>

If I understand right, I think Julia takes the Python approach to visibility: that private declarations are just suggestions denoted by a naming convention (e.g. prepending an underscore), but beyond that are not meaningfull.

---

<div class="post-metadata">

**Author:** ![mrkaspa](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mrkaspa/32/7236_2.png) [@mrkaspa](https://discourse.julialang.org/u/mrkaspa)\
**Post date:** [August 27, 2019, 7:42pm UTC](https://discourse.julialang.org/t/unexported-functions/28061/5 "2019-08-27T19:42:56Z")

</div>

do you have an example of that in a library or in the stdlib?

---

<div class="post-metadata">

**Author:** ![tviti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tviti/32/9975_2.png) [@tviti](https://discourse.julialang.org/u/tviti)\
**Post date:** [August 27, 2019, 8:27pm UTC](https://discourse.julialang.org/t/unexported-functions/28061/6 "2019-08-27T20:27:38Z")

</div>

Of the underscore convention? Doing a `Base.<tab>` at the repl makes me think it’s pretty common in the standard library (I’m greeted with a tonne of underscored names, e.g. `Base._memcpy!` and `Base._pointer`, which I presume are “private” methods.

The “using” thing is something I just learned too (I’m pretty new to the language myself):

```julia
module MyModule

function pubfun()
    println("This is a public function")
end

function _prifun()
    println("This is a private function")
end

export pubfun

end

# Un-exported stuff stays out of global namespace on "using"
using .MyModule
pubfun()
_prifun()
#=
This is a public function
UndefVarError: _prifun not defined

Stacktrace:
 [1] top-level scope at In[3]:17
=#

# But is ultimately still accessible
import .MyModule
MyModule._prifun()
#=
This is a private function
=#

```

so I guess I was wrong to say that declaring things private is totally “meaningless”, but clearly the language is using a sort of “house-sitter” philosophy to module-member visibility (i.e. you know what rooms you’re not supposed to be in, but nobody is really stopping you).

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [August 27, 2019, 8:51pm UTC](https://discourse.julialang.org/t/unexported-functions/28061/7 "2019-08-27T20:51:46Z")

</div>

I’m a firm believer in house sitter model in any interpreted language. The basic reason is that if you want to call something and the language “doesn’t let you”, you could always just copy and paste the source. Given that, why make life harder for your users?
