On Friday, 13 October 2023 at 17:38:23 UTC, bachmeier wrote:
>On Friday, 13 October 2023 at 15:34:59 UTC, kdevel wrote:
>Your functions foo
and bar
both not only make calls to interp
but they
also necessarily contain, in order to succeed, the name of the variable.
Yes
But then you can't re-use foo
with another string, e.g.
"String needing interpolation to insert ${yold} and ${ynew}."
> > Your approach creates more dependencies between unrelated components than necessary.
Then don't use it? The goal of programming is to get the right output.
Your code does not meet that requirement.
> >How do you unittest foo
and bar
?
The same as any other function.
Having the signature of foo
and bar
alone I am not able to write a unittest.
The dependencies can easily be avoided if foo
and bar
only returned the value of the computation, the results are stored in the AA given as subs
in the call to interp
.
I prefer less complicated code to code that imposes arbitrary restrictions.
In your code of foo
and bar
you have to assemble the AA and call interp
twice compared to once. I would call my approach less complicated and my foo
and bar
versions do not suffer from the arbitrary restriction of beeing applicable only to strings having a predefined variable name.