# Handling project specific variables for a library?

**URL:** <https://discourse.julialang.org/t/handling-project-specific-variables-for-a-library/72705>\
**Category:** General Usage\
**Tags:** question\
**Created:** [December 7, 2021, 10:28am UTC](https://discourse.julialang.org/t/handling-project-specific-variables-for-a-library/72705 "2021-12-07T10:28:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![volkerkarle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/volkerkarle/32/14143_2.png) [@volkerkarle](https://discourse.julialang.org/u/volkerkarle)\
**Post date:** [December 7, 2021, 10:28am UTC](https://discourse.julialang.org/t/handling-project-specific-variables-for-a-library/72705/1 "2021-12-07T10:28:50Z")

</div>

Dear community,

I am working on a numerical library. The following is only some style aspect, so nothing crucial: There are some variables/ routines which are needed for every function, and I wonder how I could simplify the code a little bit, since I am “hard-coding” everything at the moment. This is about

- Logging: Yes or no, in what detail?
- Caching: Should the outcome of the routine be saved/ loaded if available? If yes, what is the path?
- Should there be a progress bar displayed for a loop in the routine?
- Debugging: Should the routine run many checks and tests?  
For example, a typical routine looks like this (empty datapath means no caching)

```julia
function calc_y(x; loglevel=3, datapath="",debugging=false)
    pr(s,n) = n<loglevel ? println(s) : nothing
    filename = "test.h5"
    pr("Starting function calc_y...",0)
    if isfile(datapath*filename)
        # ... load ...
    else
        # ... calc something ...
        z = calc_z(x,...,loglevel=loglevel, datapath=datapath, debugging=debugging) # call another function
        y = x + z
        if debugging
            if z < 0 
                throw("z is smaller than 0! That cannot work!")
            end
        end
        # ... calc more ...
        if datapath != ""
            # ... save to filename ...
        end
    end
    return y     
end

```

Basically, this “skeleton” looks the same in every function. Is there a way to simplify this?  
Thanks!  
v.

---

<div class="post-metadata">

**Author:** ![baggepinnen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baggepinnen/32/693_2.png) [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)\
**Post date:** [December 8, 2021, 3:08pm UTC](https://discourse.julialang.org/t/handling-project-specific-variables-for-a-library/72705/2 "2021-12-08T15:08:53Z")

</div>

I believe [GitHub - JuliaPackaging/Preferences.jl: Project Preferences Package](https://github.com/JuliaPackaging/Preferences.jl) was made to facilitate having project-specific settings for packages
