# Module functions vs built-in functions

**URL:** <https://discourse.julialang.org/t/module-functions-vs-built-in-functions/54740>\
**Category:** New to Julia\
**Created:** [February 6, 2021, 4:12pm UTC](https://discourse.julialang.org/t/module-functions-vs-built-in-functions/54740 "2021-02-06T16:12:09Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![MagGeometer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maggeometer/32/21757_2.png) [@MagGeometer](https://discourse.julialang.org/u/MagGeometer)\
**Post date:** [February 6, 2021, 4:12pm UTC](https://discourse.julialang.org/t/module-functions-vs-built-in-functions/54740/1 "2021-02-06T16:12:09Z")

</div>

When you call a method that’s not exported (or even defined!) from a module, Julia matches a function defined outside the module. Is this a bug?

Example code:

```julia
module LogicalOperations

export and, or, not

function and(p, q)
    p && q
end

function or(p, q)
    p || q
end

function not(p)
    !p
end 

end # End of module

# Setup
op = LogicalOperations 
x = 5
y = 10

op.and(x > 4, y == 10) # Works as expected

op.xor(x > 4, y == 9) # Julia calls the built-in function xor, which is not part of the module!

```

---

<div class="post-metadata">

**Author:** ![Elrod](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/elrod/32/22461_2.png) [@Elrod](https://discourse.julialang.org/u/Elrod)\
**Post date:** [February 6, 2021, 4:58pm UTC](https://discourse.julialang.org/t/module-functions-vs-built-in-functions/54740/2 "2021-02-06T16:58:56Z")

</div>

Let’s say those definitions were a part of `MyPackage.jl`, a big package that also needs since logical operations.

You write some code using `MyPackage.and` and `MyPackage.not`.  
Then, one day, the author of `MyPackage` decides to refactor, and split the codebase into related packages, e.g. grouping all the logical functions into a new package called `LogicalOperations`, and has `MyPackage` now use/depend on it. Or maybe not even a new package, but a submodule within the package.

Should the code calling `MyPackage.and` and `MyPackage.not` start to error? Should this refactoring be a breaking change?

Or course, you could also say code shouldn’t depend on the internals of other packages, and that if they do they should expect random breakages.  
However, not all packages define their API as what they export, and this would be restrictive on what sort of internal reorganizing is allowed.

You could make your module a `baremodule` if you don’t want base methods to be in scope.

---

<div class="post-metadata">

**Author:** ![MagGeometer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maggeometer/32/21757_2.png) [@MagGeometer](https://discourse.julialang.org/u/MagGeometer)\
**Post date:** [February 24, 2021, 5:28pm UTC](https://discourse.julialang.org/t/module-functions-vs-built-in-functions/54740/3 "2021-02-24T17:28:18Z")

</div>

Great, thanks, I’m going to look at baremodule!

As you can tell I come from an OOP background, and certain aspects of Julia are… strange.

---

<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:** [February 24, 2021, 10:44pm UTC](https://discourse.julialang.org/t/module-functions-vs-built-in-functions/54740/4 "2021-02-24T22:44:46Z")

</div>

Is this because modules define just “namespaces” and then clearly a function which is available in the namespace of the module can be called explicitly from that namespace?

Is that one way of seeing this?

---

<div class="post-metadata">

**Author:** ![j2b2](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/j2b2/32/3387_2.png) [@j2b2](https://discourse.julialang.org/u/j2b2)\
**Post date:** [February 26, 2021, 11:59am UTC](https://discourse.julialang.org/t/module-functions-vs-built-in-functions/54740/5 "2021-02-26T11:59:35Z")

</div>

There is an implicit `using Base` at the beginning of each module, see  
[https://docs.julialang.org/en/v1/manual/modules/#Default-top-level-definitions-and-bare-modules](https://docs.julialang.org/en/v1/manual/modules/#Default-top-level-definitions-and-bare-modules)
