quote:Original post by CWizard
The same sort of optimization can be applied to normal code as well; making it shorter, cleaner, more compact, and fewer points of errors.
But that's just linear interpolation, because it's so simple. It (almost) falls to the category of initial code having a "clear sillyness". Next you might want 4-point bezier interpolation. Initially you might just type it by it's definition
p = p0*(1-x)**3+3*p1*(1-x)**2*x+3*p2*(1-x)*x**2+p3*x**3
Short and clear. Then you want speed, you use forward differencing or some other optimization algo. That one-liner suddenly expands to take more like 10 lines, in which it isn't all that clear that it's calculating a bezier curve.
So while you could have 10% of optimizations that make code 50% smaller for some particular lines, then when you take the 90% of optimizations that make code 500% larger and more complicated (and is where the speed increase really comes from), there's a large net increase in complexity and code length.
Maybe you only do this 10% and leave it at that, I don't know. But for me, it's absurd to hear that optimizations tend to make code cleaner and shorter ('tend', as if that was common). If that were the case, I doubt Knuth would've even said his famous words.
[edited by - civguy on November 9, 2003 4:48:15 AM]