Ask HN: Are there any ways to avoid conditional logic?
sitting here at work staring at about 30 lines of conditional logic.
got me thinking, is there a design paradigm that will avoid conditionals all together and yet achieve the same thing? Using java and SQL if it makes any difference.
6 comments
[ 2.7 ms ] story [ 23.9 ms ] threadFeel free to fudge variable names, function names, etc.
See, for example:
https://refactoring.guru/replace-conditional-with-polymorphi...
Note that this can be made to work for simple conditionals. It's probably not going to help if you have really complicated conditions, the kind where you need to break out your old discrete math book and draw a truth table and use DeMorgan's Law and all of those other "rules of inference" to work out what happens.
Note also that there are (practical) limits to this in general. Creating lots of classes and overridden methods just to get rid of some conditional logic has the potential to make things even more byzantine and confusing, not less. But done well, and in limited doses, it can be a viable strategy.
If those design paradigms don't work, we've actually had a bit of luck using BPMN and executing it via Drools. This is not "easy" per say but our processes and decision tree were not simple either.
Wishing there was a simpler and modern BPMN like language that supported CDI directly.