# Cleaner way of passing many arguments between functions

**URL:** https://discourse.julialang.org/t/cleaner-way-of-passing-many-arguments-between-functions/96771
**Category:** General Usage
**Created:** [March 29, 2023, 10:28am UTC](https://discourse.julialang.org/t/cleaner-way-of-passing-many-arguments-between-functions/96771 "2023-03-29T10:28:43Z")
**Posts on this page:** 1
**Showing post:** 7

<div class="post-metadata">

### Author: ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)
#### Post date: [March 31, 2023, 12:49pm UTC](https://discourse.julialang.org/t/cleaner-way-of-passing-many-arguments-between-functions/96771/7 "2023-03-31T12:49:42Z")

</div>

> [@f.ij](#):
>
> ```julia
> function mainAlgo(someRef, otherStruct, argStruct)
> @registerStructVars argStruct ArgStruct
> while someRef[] = true
> #do function for some of the arguments
> end
> mainAlgo(someRef, OtherStruct, createArgStruct(OtherStruct) )
> end
> 
> ```

This seems weird and non-idiomatic to me — you’re basically using [tail calls](https://en.wikipedia.org/wiki/Tail_call) to write a loop in an imperative language (which may overflow the stack since Julia [doesn’t do tail-call optimization](https://discourse.julialang.org/t/does-julia-have-tail-call-optimization/64101)). Why not simply write a second loop, for example:

```julia
function mainAlgo(someRef, otherStruct, argStruct)
     a, b, c, d = argStruct # unpack the variables for convenience and mutation
     while outerloop_condition
          while someRef[]
               #do function for some of the arguments
          end
          # update the arguments for the next outer iteration
      end
end

```

(The `someRef[]` check confuses me, too. Are you thinking of running this loop asynchronously and having some other thread/task update `someRef[]` to control when `mainAlgo` terminates? That’s a pretty confusing control-flow structure. If not, why use a `Ref` argument?)

---

_[View the full topic](https://discourse.julialang.org/t/cleaner-way-of-passing-many-arguments-between-functions/96771)._
