Thanks for the comments. I’ll give a simple example based on this function in my package. Say one has the following function:
function foo!(a,b,c,d,e,f) # a long list of arguments, some of which remain constant, some mutated
g,h,i,j,k = 1,2,3,4,5 # more internal variables
bar!(a,b,c,g,h,i)
baz!(d,e,f,i,j,k)
end
Where, for readability purposes, there are functions that operate on a bunch of variables. However,usually one hears that when there are lots of variables, one should use some class to make the code cleaner, like the following:
function foo!(input_struct) # input structs in corporates variables a - k
bar!(input_struct)
baz!(input_struct)
end
But that, in my specific use case, has slowed the function down quite a bit, therefore I’m looking for alternatives. Of course, it’s all for readability’s sake only. I’ve tried in the past to use something like the following:
function foo!(a,c,f,constants) # constants is some named tuple of variables that don't get mutated at all
bar!(a,c,f,constants)
baz!(a,c,f,constants)
end
But not only did I find it to even be a bit more confusing, it slowed the code down slightly. Benchmarking that function on an input used to average at 1 ms, but using the named tuple slowed it down to an average runtime of 1.3 ms (no GC time)
Now, I may have accidentally ommitted other factors which could’ve slowed the code down the second time round, but I just wondered if there’s a more “aesthetically elegant” way to write the code.