# Where to put a bunch of constants?

**URL:** https://discourse.julialang.org/t/where-to-put-a-bunch-of-constants/76885
**Category:** General Usage
**Tags:** question, constants
**Created:** [February 22, 2022, 7:05am UTC](https://discourse.julialang.org/t/where-to-put-a-bunch-of-constants/76885 "2022-02-22T07:05:09Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![marianoarnaiz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marianoarnaiz/32/19377_2.png) [@marianoarnaiz](https://discourse.julialang.org/u/marianoarnaiz)
#### Post date: [February 22, 2022, 7:05am UTC](https://discourse.julialang.org/t/where-to-put-a-bunch-of-constants/76885/1 "2022-02-22T07:05:09Z")

</div>

Hi everyone.  
I am developing a set of scripts for geophysics in Julia and at the core of many of my codes I have a bunch of values (maybe they can be consider Julia Constants at some point) but in general they are physical constants (like the Earth’s mean Radius or the Core’s Mass).

Now, many of the users won’t bother changing this, but someone might. Is there a good way to place them in a file for easy modification? What would you recommend?

---

<div class="post-metadata">

### Author: ![jar1](https://avatars.discourse-cdn.com/v4/letter/j/c0e974/32.png) [@jar1](https://discourse.julialang.org/u/jar1)
#### Post date: [February 22, 2022, 8:07am UTC](https://discourse.julialang.org/t/where-to-put-a-bunch-of-constants/76885/2 "2022-02-22T08:07:20Z")

</div>

Some are available in  
[https://juliaphysics.github.io/PhysicalConstants.jl/stable/constants/](https://juliaphysics.github.io/PhysicalConstants.jl/stable/constants/)

---

<div class="post-metadata">

### Author: ![Jeff\_Emanuel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeff_emanuel/32/15440_2.png) [@Jeff\_Emanuel](https://discourse.julialang.org/u/Jeff_Emanuel)
#### Post date: [February 22, 2022, 5:42pm UTC](https://discourse.julialang.org/t/where-to-put-a-bunch-of-constants/76885/3 "2022-02-22T17:42:08Z")

</div>

> [@marianoarnaiz](#):
>
> set of scripts

Scripts bad, modules good.

> [@marianoarnaiz](#):
>
> but someone might…What would you recommend?

I recommend against such speculative generalization. If you must, because you think the users might try to operate on other celestial bodies, perhaps your functions can accept a Planet parameter, and the module would provide a function to return an earth instance of Planet. The functions may even make the planet parameter default to earth.

---

<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 22, 2022, 5:49pm UTC](https://discourse.julialang.org/t/where-to-put-a-bunch-of-constants/76885/4 "2022-02-22T17:49:07Z")

</div>

One way to structure it, without relying on global constants:

```julia
julia> module MyPackage
           export myfunction, MyConstants
           Base.@kwdef struct MyConstants
               a::Int=10
               b::Float64=1e-3
           end
           function myfunction(x;constants=MyConstants())
               (;a,b) = constants
               return a*x^b
           end
       end
Main.MyPackage

julia> using .MyPackage

julia> myfunction(5.0)
10.016107337527293

julia> myfunction(5.0,constants=MyConstants(b=1e-2))
10.162245912673256

```
