49
Push Ifs Up And Fors Down
(matklad.github.io)
Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!
Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.
Hope you enjoy the instance!
Rules
Follow the wormhole through a path of communities !webdev@programming.dev
The point is that if the predicate is evaluated at runtime then the compiler plays no role because there is no compile-time constant and all code paths are deemed possible.
I understand that you're trying to say that compilers can leverage compile-time constants to infer if code paths are dead code or not.
That's just a corner case though. Your compiler has no say on what code paths are dead if you're evaluating a predicate from, say, the response of a HTTP request. It doesn't make sense to expect this hypothetical scenario to be realistic when you have no info on where a predicate is coming from.
They're talking about moving the calculation of the if condition outside of the loop. Which the original commenter mentioned. https://en.m.wikipedia.org/wiki/Loop-invariant_code_motion
You are the one that brought up dead code elimination.