It really happened, legacy programmers tales
Fairy tales always start with “Once upon a time”, and programmers tales starts with “when I was at a client”…
Two days ago I was a client, and the discussion turned to bad code bases, as it often does. One story that I had hard time understanding was the Super If.
Basically, it looked like this:
I had a hard time accepting that someone could write an if condition that long. I kept assuming that they meant that the if statements were 50 lines long, but that wasn’t the case.
And then yesterday I had an even more horrifying story. A WCF service making a call to the database always timed out on the first request, but worked afterward. What would be your first suspicion? Mine was that it took time to establish the database connection, and that after the first call the connection resided in the connection pool.
They laughed at my naivety, for it wasn’t connecting to the database that caused the timeout, it was JITting the method that the WCF service ended up calling.
Yep, you got that right, JITting a single method (because the runtime only JIT a single method at a time). I had even harder time believing that, until they explained to me how that method was built:
Some interesting stats:
- It had a Cyclomatic Complexity of either 4,000 or 8,000, the client couldn’t remember.
- The entire Rhino Mocks codebase fits in 13,000 LOC, so this single method could contain it several times over.
But you know what the really scary part is?
I upgraded from Super If to Black Hole Methods, and I am afraid to see what happen today, because if I get something that top the Black Hole Method, I may have to hand back my keyboard and go raise olives.