3 ms·
It's not quite as crazy as it sounds. It was a case of laziness and a belief that he was smarter than the compiler, rather than a lack of knowledge of basic flo
by jofer 7y ago
It's not quite as crazy as it sounds. It was a case of laziness and a belief that he was smarter than the compiler, rather than a lack of knowledge of basic flow control.
For context, the "ten-item-only data transfer tool" was a plugin to a much larger piece of software with a Qt-based gui. He copy-pasted an example from the vendor that used a QLineEdit input widget ten times because he couldn't be bothered to look up how to use a QListWidget or something similar.
The "avoidance of loops" I was referring to was mostly in the inner loops of volumetric image processing routines. A lot of things we worked on were domain-specific operations that are vaguely analogous to a convolution -- there's usually a moving window operation. He'd happily loop over the volume, but insist on writing the inner loop (the actual moving window) as repeated copy-pasted lines.
He was basically doing manual loop unrolling, which could actually make sense in this context. (The codebase was C masquerading as C++.)
However, the compiler was perfectly capable of optimizing a loop for the exact use cases he was working with. There was zero benefit manually unrolling a nested loop for a 5x5x11 or 3x3x7 window (in once case he did it for a 25x25x51 window -- 31k lines of C++... Generated with Perl... Yeah...)
On the geology note, palentology is actually a fairly niche field. I wouldn't assume that every geologist has taken a paleo class. It's usually on the "take 3 of these 5" requirement list in undergrad, and it's not something you take at a graduate level unless that's your specialty. I certainly took a couple paleo/evolutionary biology classes, but it's useful for what I used to do. It wouldn't shock me if someone primarily doing reservoir modeling didn't know what an ammonite was.
- tempguy9999 7y agoAh, thanks for the loopy explanation. Actually any loop unrolling to that extent is counterproductive as it will simply burst the instruction cache, which causes expensive reloads from further down the cache hierarchy, whereas loops can be minimal or even zero overhead. I'd be really curious to know how much performance that cost. re. ammonites, ok, thanks for explanation!