Run parts of other files from a loop

Maybe use a data format, such as JSON or TOML or YAML, to define the parameters, rather than code?

(Forcing yourself to include parameters into the global namespace is asking for trouble in the long run. e.g. suppose you want to run many simulations in parallel.)

Of course, sometimes you want code to set up the simulation parameters, e.g. if you are running a parameter sweep. But in this case, I would usually recommend organizing things the other way around — have your parameter-generating code call the computational code (as a subroutine in a package) rather than the opposite. As a general principle, writing nontrivial computational code as global “scripts” makes it inflexible and non-reusable in the long run. See also Organizing code in Julia.

Here’s a nice excerpt on a related subject from a great (language-agnostic) book I would recommend, The Pragmatic Programmer:

3 Likes