# Parameter Stores to Struct or not to Struct, what is the julian way?

**URL:** <https://discourse.julialang.org/t/parameter-stores-to-struct-or-not-to-struct-what-is-the-julian-way/30362>\
**Category:** New to Julia\
**Created:** [October 27, 2019, 11:06am UTC](https://discourse.julialang.org/t/parameter-stores-to-struct-or-not-to-struct-what-is-the-julian-way/30362 "2019-10-27T11:06:35Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon92994695](https://avatars.discourse-cdn.com/v4/letter/a/ce7236/32.png) [@anon92994695](https://discourse.julialang.org/u/anon92994695)\
**Post date:** [October 27, 2019, 11:06am UTC](https://discourse.julialang.org/t/parameter-stores-to-struct-or-not-to-struct-what-is-the-julian-way/30362/1 "2019-10-27T11:06:35Z")

</div>

I am making a simulation package in Julia. There are maybe 10-20 different parameters that must be user defined(not derivable from other means) passed around different functions(mostly in pieces but still all need to be entirely in scope at some point).

For the sake of the sanity of the end user I’d like to put these into some object: potentially a struct, maybe a Dict? Mostly for convenience, otherwise a user may have to make a function call with 10-20 different keywordless parameters. Another set of alternatives to consider could be to have a “template” with a bunch of globals, or even a UI (kind of forces the workflow of the end user though…), a csv/json type file format?

What’s the Julian way of handling these scenarios?

---

<div class="post-metadata">

**Author:** ![anon92994695](https://avatars.discourse-cdn.com/v4/letter/a/ce7236/32.png) [@anon92994695](https://discourse.julialang.org/u/anon92994695)\
**Post date:** [October 27, 2019, 11:07am UTC](https://discourse.julialang.org/t/parameter-stores-to-struct-or-not-to-struct-what-is-the-julian-way/30362/2 "2019-10-27T11:07:44Z")

</div>

Another alternative would be to have it all in a struct, and make all other functions reference objects of that type? That would be a more classic FP type design I think.

---

<div class="post-metadata">

**Author:** ![cserteGT3](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/csertegt3/32/8283_2.png) [@cserteGT3](https://discourse.julialang.org/u/cserteGT3)\
**Post date:** [October 27, 2019, 11:25am UTC](https://discourse.julialang.org/t/parameter-stores-to-struct-or-not-to-struct-what-is-the-julian-way/30362/3 "2019-10-27T11:25:57Z")

</div>

I think [Parameters.jl](https://github.com/mauro3/Parameters.jl) is what you’re looking for.

---

<div class="post-metadata">

**Author:** ![Tero\_Frondelius](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tero_frondelius/32/7629_2.png) [@Tero\_Frondelius](https://discourse.julialang.org/u/Tero_Frondelius)\
**Post date:** [October 27, 2019, 11:26am UTC](https://discourse.julialang.org/t/parameter-stores-to-struct-or-not-to-struct-what-is-the-julian-way/30362/4 "2019-10-27T11:26:52Z")

</div>

`@with_kw` macro from [Parameters.jl](https://github.com/mauro3/Parameters.jl/blob/master/README.md) is really cool. It also defines the `show` methods automatically. I strongly recommend it in any case.

---

<div class="post-metadata">

**Author:** ![anon92994695](https://avatars.discourse-cdn.com/v4/letter/a/ce7236/32.png) [@anon92994695](https://discourse.julialang.org/u/anon92994695)\
**Post date:** [October 27, 2019, 11:34am UTC](https://discourse.julialang.org/t/parameter-stores-to-struct-or-not-to-struct-what-is-the-julian-way/30362/5 "2019-10-27T11:34:00Z")

</div>

Awesome!

Thanks both of you this looks like exactly what I wanted!

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [October 27, 2019, 2:02pm UTC](https://discourse.julialang.org/t/parameter-stores-to-struct-or-not-to-struct-what-is-the-julian-way/30362/6 "2019-10-27T14:02:06Z")

</div>

Also look at `Base.@kwdef`.

---

<div class="post-metadata">

**Author:** ![aaowens](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aaowens/32/12101_2.png) [@aaowens](https://discourse.julialang.org/u/aaowens)\
**Post date:** [October 27, 2019, 6:10pm UTC](https://discourse.julialang.org/t/parameter-stores-to-struct-or-not-to-struct-what-is-the-julian-way/30362/7 "2019-10-27T18:10:48Z")

</div>

I’ve been using Parameters with named tuples, but I might use [https://github.com/JuliaDiffEq/LabelledArrays.jl#relation-to-namedtuples](https://github.com/JuliaDiffEq/LabelledArrays.jl#relation-to-namedtuples) in the future as a replacement. I like that I get vector functionality for free, and it makes all the elements the same type, which improves compilation time.

One advantage of using a struct and Parameters is that you can make use of multiple dispatch. This is useful if you have multiple models which use different sets of parameters.
