Tragedy of the Doubtful Solution
The Background I (re)tell a story frequently about a place I worked in the 90s. There was a piece of code with an absurd cyclomatic complexity score, running literally hundreds of lines in length, and being called from myriad places in the code base. The code was written to check to see if two ranges were overlapping. Being written in a poor 4GL, it took four parameters representing the starting and stopping dates of two time ranges. Such a simple task for the code to be so horrible and lengthy. In C it would look rather like this: bool ranges_are_overlapping(int a, int b, int c, int d){ } It quickly became clear to the most casual reader that the ranges were a..b and c..d. Well, sort of. The code was defensive and was written with the understanding that the range-defining arguments could be somewhat unordered: if ( (a<b) && (c<d) ) { // blah blah } else if ( (a==b) && (c<d) ){ // blah blah } else if ( (a>b) && (c<d) ){ ...