4 ms·
Decision table's are really good at representing complex rules, in a language with pattern matching u can convert a nested if else block to a decision table tha
by aszen 6y ago
Decision table's are really good at representing complex rules, in a language with pattern matching u can convert a nested if else block to a decision table that is much more readable, as an example see https://github.com/finos/morphir-examples/blob/master/src/Morphir/Sample/Rules/Direct.elm https://github.com/finos/morphir-examples/blob/master/src/Mo...
- exdsq 6y agoThat’s a _really_ nice example! Might suggest this in code reviews as I come across quite a few complex nested if/elif blocks
- emmanueloga_ 6y agoindeed! really nice. In the past I have just worked some hairy logic on a spreadsheet and just manually migrate it to code / nested conditionals. This other article [1] shows some really cool ways to writes decision tables using structured editing UI. I wish structured editors where more commonplace! 1: https://medium.com/@markusvoelter/the-evolution-of-decision-tables-80ce77bf984c https://medium.com/@markusvoelter/the-evolution-of-decision-...
- ajuc 6y agoYou can also use sth like Map<List<Boolean>, Result> in languages with no pattern matching. Sadly map literals aren't pretty in some of these languages, but it's still better than a bunch of nested if-then-elses or switches.
- exdsq 6y agoGood point! I don’t see why languages don’t adopt pattern matching (unless the grammar really breaks it for whatever reason)