3 ms·
Let's say you have SwingButton and FLTKButton. I'd have a common Button that uses the fancy new pattern matching features. I like me some if statements. Debugg
by winrid 3y ago
Let's say you have SwingButton and FLTKButton. I'd have a common Button that uses the fancy new pattern matching features.
I like me some if statements. Debugger friendly.
- blowski 3y agoSome 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.
- viraptor 3y agoThen you have an if statement per every place where you're operating on one or the other type. It may be very few places and it may be fine like that. It may be 4 options times a hundred paces and then it's not fine anymore. I'm not sure what you mean by debugger friendly. Your debugger knows what types things are.