Where to put a bunch of constants?

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

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


5 Likes