3 ms·
Some engineers see a chain of if statements as the problem, others see it as the solution. Who’s right is very subjective.
by blowski 3y ago
Some engineers see a chain of if statements as the problem, others see it as the solution. Who’s right is very subjective.
- djbusby 3y agoUse switch!
- viraptor 3y agoI'd go with: who's right depends on the code in question, with a large area of "it's a wash" in between. The extremes are not subjective.
- tacitusarc 3y agoI strongly disagree with this. If statements have caused me more headaches than any other single programming concept. This is not subjective. When coders use if statements to replace polymorphism, it scatters logic throughout many different files. This has two extremely negative effects: first, to understand the reach of a single component, you need to understand the entire codebase. Second, when multiple developers are working in tandem, you are almost guaranteed to go through an incredibly difficult rebase process since the structure requires everyone to work on the same files. If statements are useful for validation and bootstrapping decisions*, but if you embed them in your model as part of the operational structure, you’re making a rookie mistake. *High performance software and scripts are the exception to most rules.