> Any time you are making decisions based on information that you know at compile time, you could apply this technique
I’d go further. Most business requirements are known at compile time.
Take the simplest example, dispatching a function based on a condition. If A then do_X, if B then do_Y.
People often reach for elaborate design patterns, dependency injection, or polymorphism here. But why?
If the decision logic is static, don’t turn it into a runtime problem.
Inline the code. Move the ifs up. Write clear, specific functions that match your domain knowledge instead of abstracting too early…
I’d go further. Most business requirements are known at compile time.
Take the simplest example, dispatching a function based on a condition. If A then do_X, if B then do_Y.
People often reach for elaborate design patterns, dependency injection, or polymorphism here. But why? If the decision logic is static, don’t turn it into a runtime problem.
Inline the code. Move the ifs up. Write clear, specific functions that match your domain knowledge instead of abstracting too early…
Don’t make compile time problems runtime ones.