On Wed Nov 22 19:13:18 2023 +0000, Zebediah Figura wrote:
My understanding is that the for-if anti-pattern is when the iteration
is not necessary, and I think it is in this case. Albeit, I can make it more readable at the expense of making it more verbose, I added copy_propagation_get_value_at_time(). Okay, apparently this is the name Raymond Chen gave to something else. What I mean is cases like
for (...) { if (...) found = true; } if (!found) ...
(or variations on this, e.g. checking the iterator after the loop instead of using a separate flag variable). I have a strong personal dislike for this pattern. I think it's always more idiomatic and simpler to have a lookup helper, that returns NULL or false or whatever if the thing isn't found. I.e. not getting rid of the loop, but making it into a helper function.
Okay, I will try to remember to use lookup helpers in these cases, I agree that is more idiomatic.