37
Root
4y

Confession:

I rely on WolframAlpha to simplify Boolean logic a little too much.

Comments
  • 3
    If it works...
  • 8
    Do you often work with complex Boolean math? I don't come across it much. In fact the project I inherited is full of

    if(true) {
    return true;
    }
    else{
    return false;
    }
  • 2
    Jesus said, but let your communication be, Yea, yea; Nay, nay: for whatsoever is more than these is a parity error.
  • 11
    @AlgoRythm Yeah.

    I work in finance (fintech?) and the codebase is quickly heading towards flag hell.

    There’s a lot of complicated logic around when to do something, when to show things, etc. and of course the PM always gives complicated conditions, and they are inverses of how I would represent them in code. (And some of the conditions are compound, like `.viable?` means “not closed and not suspended”)

    Currently I’m refactoring something that’s a long list of nested ifs/ifelses with various compound conditions, and converting it into a set of functions with guards. So much easier to understand. But this involves simplifying the messy boolean logic trees, and inverting many of the branches.

    And ofc writing specs that ensure the logic is correct, including negative tests which involve more inversions.

    It’s been fun 😅
  • 1
    Hmmm isn't it just simple to understand code if boolean logic actually follows if-else code-like structure.

    Maybe you might have a lot of these conditional flags for which combinations may very well be closures/lambdas/whatever.

    Edit: nvm your comment just updated for me @Root
  • 4
    @3rdWorldPoison

    Imagine, if you will, a world filled with branching logic trees. For this particular tree, all of the various endpoints modify or replace a shared array, or modify data that other endpoints will eventually inject into said array. Determining if the array will have a particular bit of data involves climbing through all of its parent branches, and often traversing the entire tree. Adding new data also involves understanding the entire tree.

    Now, imagine a set of boxes with clearly defined rules atop. If the rules are met, the box is opens; if they are not, it remains locked. Constructing the array mentioned above amounts to opening each box in turn and gathering the contents. If you desire a particular bit of data, you need only check its box. Adding new boxes is likewise trivial.
  • 1
    @Root

    As someone who got turned upside down a bit just yesterday with just a handful of true false cases (with a bunch checks for 'not false' and 'is false' and now the same with true ... GUIES STOP) in a row ... that does not sound fun.

    On the other hand if it works in the end, does sound really fun.
  • 2
    @Root nice explaination 10/10. I imagine I won't see the essence of it without understanding the scale of the problem.

    Quite interesting to see the approach nonetheless.
  • 2
    WolframAlpha is amazing! no shame in using a great tool.
  • 2
    I rely on Regex101.com way more than I should.
  • 0
    Same here. When I cant use KV-Maps this is pretty much the easiest option.
  • 0
    For complex boolean logic I always consider introducing proper types and leveraging polymorphism instead of extracting functions with guards. But that could be a first step towards getting stuff manageable and testable in smaller units.
  • 2
    That is great I didn’t know WolframAlpha could do that. I have been using Karnaugh Map to simply boolean expressions.
  • 1
    @l0rdkr0n0s WolframAlpha is amazing but they do a poor job in marketing and explaining what it can do for you.
    And the interface hasn't been updated since they launced the website in 2009. So the appearance may seem dated and scare new user away.

    😄 i showed WolframAlpha to a high school student once and he thanked me so much, as he hates math homework. With WolframAlpha homework becomes obsolete as the main skill of today lies in the knowledge where to get knowledge.
    Google-fuu, YouTube tutorials, are the essential skills of today.
Add Comment