Just another example of missing string interpolation
kdevel
kdevel at vogtner.de
Fri Oct 13 15:34:59 UTC 2023
On Friday, 13 October 2023 at 14:31:01 UTC, bachmeier wrote:
> [...]
> An example of a pattern I sometimes use:
>
> ```
> string foo(string s) {
> // Do a computation and substitute the result into s
> // return the new s
> ```
At which position? Which pseudo-variable is substituted in `s`?
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.
>```
> }
>
> string bar(string s) {
> // Do a computation and substitute the result into s
> // return the new s
> }
>
> string s = "String needing interpolation to insert ${y} and
> ${x}.";
> string s2 = foo(s);
> string s3 = bar(s2);
> ```
Your approach creates more dependencies between unrelated
components than necessary.
How do you unittest `foo` and `bar`?
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`.
More information about the Digitalmars-d
mailing list