3
lorentz
4d

It often feels like the logic and the equivalent final application code have nothing to do with each other.

Logic: Find the only element in this list that matches criterion, or the first element in this other list, or none. If the first list has multiple matches, fail.

Application: Produce information about the criterion checks for all elements in both lists for info logging. Find any elements in first list that match. Save the number of matches for an optimization that relies on a lot of assumptions about the search criterion that are only ever expressed in doc text. If one, return, if multiple, fail. Otherwise find first match in second list, produce debug hint on why the preceding elements in that list didn't match by aggregating the criterion check info. If multiple matched in second list, check highly specific interdependency, and if absent, produce warning about ambiguity. Return first match if any.

The first can be beautifully expressed as a 5 line iterator transform. The second takes 3 mutable arguments (cache, logger, criterion because it also may cache and log), must compute everything eagerly and has constraints that are neither strictly necessary for a correct implementation nor expressible in the type system.

Comments
  • 0
    That's actually a fun task and contains already more businesslogic than most tasks I've had. Ik did implement huge processes but there were not much algorithms like that behind it. Calculating tax over invoices, discounts and statistics are the things I did a lot, so it's not weird that work on something completely different private. Sadly, this is where dem monehh is.
  • 1
    @retoor This is actually hobby stuff. I wouldn't dare spend the client's precious budget on adding debug logging when I write the code, it's clearly far more efficient to add it each time someone needs it and then never check it in so they don''t commit unnecessary changes to additional files.
Add Comment