I am wondering how everyone properly defines structs for their own modules. I read that in Julia, one usually defines one base module where general packages are imported, file dependencies to own functions are included via \include … and finally relevant functions are exported.
Usually, there is also a file included that first defines structs that serve as output of user defined functions - here comes my question. How do you best define structs if you create several functions that create similar ouput?
- One might be interested to generate hidden Markov models; there are many examples (basic HMM, semi HMM, factorial HMM…), and, depending on the model, there are different kinds of interesting output.
- One might be interested to do Bayesian inference via MCMC, but depending on the algorithm (HMC, SMC, Gibbs, etc.) there are different output statistics of interest.
I have looked through several popular packages, and - to my crude knowledge - people usually define first a general class, and then subclasses for each individual algorithm via a struct command. One could, alternatively, use the Parameters module, define only one struct with elements of all similar algorithms (i.e. output statistics of HMC, SMC, Gibbs sampler all in one class) and assign a default value of nothing/undefined to it. You then populate this struct with only the relevant elements for each algorithm, the rest will be kept as undefined.
I have not seen anyone using the second method, but it seems to me it has some advantages. For instance, I can actually populate the struct by the corresponding keyword (in any order?) when I create such a struct - and everything that is not named will just have no nothing as default value. This is also of advantage if I happen to have another idea for my struct and a posteriori want to add an additional element to the struct. In the first popular method, I would need to include that new element in all files where I previously defined that struct. With the “Parameters” method, I would only need to include it
where it matters and for all other cases it defaults to nothing. Seems especially nice if the module is still very new and experimental.
So, why is the first method so dominant in all popular modules? What would you recommend for the 2 examples I stated above? I would love if the Parameters module functions would be included in the base version of Julia, it seems super helpful.
Best regards and thank you for your input!