I have been using Julia for about a week using Vscode as my IDE. Simple examples not problems. My task at hand it to convert well structure code (in VBA) to Julia - I am solving a system of 130 ODE’s (initial value problem) with the solution taking way too long in VBA. My VBA code uses 100’s of global parameters (Private a, b, c … as Single (or Double or String or Integer) that are used in multiple subroutines in the VBA. Very convenient method for sharing parameters and keeping code tightly contained in sub-routine structures without the need to pass great long strings of arguments. I am lost as how to do this in Julia - I haven’t been able to find anything on structuring Julia programs. Can anyone help? Peter
Don’t use globals, they say… I’d wrap the parameters in a struct (or named tuple), you can then pass that as a single parameter to the functions. There are a bunch of helpers around to make things a bit easier. Have a look at
Base.@kwdef, https://github.com/mauro3/UnPack.jl, and/or https://github.com/mauro3/Parameters.jl.
Received wisdom is that global state is “evil” (googling it will give many entries). You mention it’s a well structured VBA code, but where’s the structure if there are hundreds of global parameters?
You probably want to define your own data structures, which is quite straightforward.
So instead of many arguments:
function f(a, b, c) return a + b + c end
You can group it in a struct (or e.g. a namedtuple):
struct MyData a b c end function f(data) return data.a + data.b + data.c end
The documentation can be found here:
Many thanks – that looks really interesting. I will investigate further. Yes, I was scared off by using Global
Thank you. I will take a look. Regards Peter Brisbane Australia