Not only that, map generalizes to any collection---in fact to any functor at all. It allows for much better modularity in the code. On Tue, Jun 10, 2014 at 12:40 PM, Henry Baker <hbaker1@pipeline.com> wrote:
Decent compiler optimizations can move most array-bounds checks out of loops. If yours can't, you need a better compiler.
In no case should you eliminate an array-bounds check that your compiler (or you) can't rigorously prove isn't required.
Part (most) of the problem with array bounds checking was the idiotic separation of the loop index from the array itself.
for i=0 to n-1 do something with array[i]
The compiler has to figure out for itself that i is within the bounds of array, and this is (in general) very difficult.
However, if I say map(lambda(x) do something with x, array), then map _already knows_ that we are within bounds, so no further checking is required. And no, there is no performance penalty for using a mapping operation plus a lambda; the mapping gets open-coded, as does the lambda. Believe it or not, this sort of optimization is actually easier than the Presburger arithmetic necessary to handle many array index optimizations.
So most of the stupid array checks are due to bad programming language design.
Yes, there will be cases where the array index operations become more interesting; Knuth loves these sorts of things.
Nevertheless, perhaps 95-98% of the array index operations can be done with various mapping & folding operations, which eliminate the need for run-time index checking.
At 10:45 AM 6/10/2014, Joerg Arndt wrote:
Fortran, C/C++, etc., didn't bother with array bounds checking.
I do not think that I want to check those bounds 10^9 times a second when I _know_ it is useless.
Perhaps 90% of software bugs have to do with array bounds violations. (I may have been the only person to actually utilize PL/I's array bounds checking code; it found innumerable bugs.) Oops!
Ach ja!: valgrind exists. (Yes, I did find a few bugs in my collection of high performance crappyness; valgring: good!).
During runtime in a shipped product? Erm, please no. And then, maybe, yes: people are so used to Microsoft performance that they'd never notice.
_______________________________________________ math-fun mailing list math-fun@mailman.xmission.com https://mailman.xmission.com/cgi-bin/mailman/listinfo/math-fun
-- Mike Stay - metaweta@gmail.com http://www.cs.auckland.ac.nz/~mike http://reperiendi.wordpress.com