Geek Pride
Imagine a cartoon. One character reaches into the mouth of another. The arm goes in to the shoulder, they grab hold of something, and PULL the victim inside-out.
I did that to a computer program today - a big forest of nested if-then-elses, 3-4 layers deep. This code gets executed at least 10+ times whenever someone loads a page from the system, and is almost guaranteed to be a performance bottleneck as soon as we get above about 20 simultaneous users.
By the time I was done, 412 loooong lines of code had been reduced to 165 shorter lines, it's faster to execute, and I'm within striking distance of (1) sharing huge slabs of code with another, very similar, function and (2) replacing dozens of string comparisons with an integer-based switch/case.
I appreciate that a large proportion of my readers would understand the above better if it was written in Martian, but I reckon that's a good afternoon's work.
Of course, when I go in tomorrow, I'm likely to find that the overnight build has exploded in flames, and no doubt in three weeks' time we'll find some hideous bug I caused in the process, but...
I did that to a computer program today - a big forest of nested if-then-elses, 3-4 layers deep. This code gets executed at least 10+ times whenever someone loads a page from the system, and is almost guaranteed to be a performance bottleneck as soon as we get above about 20 simultaneous users.
By the time I was done, 412 loooong lines of code had been reduced to 165 shorter lines, it's faster to execute, and I'm within striking distance of (1) sharing huge slabs of code with another, very similar, function and (2) replacing dozens of string comparisons with an integer-based switch/case.
I appreciate that a large proportion of my readers would understand the above better if it was written in Martian, but I reckon that's a good afternoon's work.
Of course, when I go in tomorrow, I'm likely to find that the overnight build has exploded in flames, and no doubt in three weeks' time we'll find some hideous bug I caused in the process, but...
no subject
I've done something like that a few times, although not on quite the same scale. Looking through someone else's code, spending an hour trying to understand exactly why they've done something convoluted and complicated, gradually coming to the realisation that actually there isn't any good reason for it, and ripping the entire wodge out and replacing it with a few alternative lines of code. A sort of `cruftectomy', I guess.
It's a nice buzz when it works, though - here's hoping the overnight build remains resolutely unimmolatory :)
nicholas
no subject
Then the US wing of the company got to work modifying the system for the American market. Some manager noticed that the UK team hadn't been quite as aggressive as they might have been with the use of the sign bit in one of the registers, and fired off a really harsh memo to higher management on both sides of the Atlantic, slating the UK team for this oversight. This obscenely wasteful squandering of valuable bits was duly `corrected', and the system installed in a test car and sent off round the track.
I'm told that everything was fine up to 127 mph, at which point the car promptly flipped over on its back in a rather spectacular and aggravating manner - having abruptly decided that it was now travelling 128 mph in reverse.
nicholas
no subject
::crosses fingers::
no subject
no subject
no subject
Imagine a branching tree of if-then-elses, but with the same decisions deep in each fork. That's how I "inverted" it - taking one of the deeper if-then statements and pulling it out so it happened first - thereby eliminating a swathe of duplication. I also applied a few "else if" clauses to reduce repeated evaluation of string comparisons.
I'm probably going to have to answer a charge that I made the code MORE convoluted, but I reckon it was worth it for the performance improvement and centralised definition of constants. I think, once people grok it, my new code is actually no more complex than the old code, just very different in its approach to the problem.
no subject