sebstefan
4 hours ago
>Decision Tables
>Instead of hardcoding the logic inside our function, we can place each if-else block in its own function and put those functions in an array, forming a decision table.
In my experience this is always an unwelcome addition to a codebase and a worse choice than just several lines of ifs
* You've added a level of indirection
* You've written the code in a less straightforward way, your fellow programmer might now need to spend more time understanding what they're looking at and wondering why you wrote it like that instead
* The ifs are still there, it's not inherently simpler just because it's tucked away
* They could've been tucked away in functions, which have the benefit of having names, making them (maybe) a bit more self-explanatory?
But most importantly
* You've introduced an abstraction, and it might be the wrong one
What if one of the conditions need to have a different kind of follow up?
Some people then build two separate decision tables depending on what the follow up needs to be, some take the outstanding "if" out of the decision table and add it back in the regular control flow, which kind of highlights the problem on its own, but...
Some other people double down and make the decision table a more robust abstraction, and in my opinion this is the worst outcome. You end up with some bullshit Predicate & PredicateEngine, callbacks, why not maybe async, and at that point you need to look at it and realize "We're making a framework, and we will eventually need to extend it until it encompasses the entire possibilities of the language's control flow, except with massive overhead, and nothing of value being created"
hansvm
an hour ago
All they really did was flatten the if/else to remove a few layers of nesting. It's not a bad idea in the abstract (not suitable everywhere of course), even if you don't like their particular implementation.
// Original
if a
if b
else
else
if b
else
// New
if not a and not b
if not a and b
if a and not b
if a and b