On 3/18/15 4:54 PM, David Gileadi wrote:
On 3/18/15 4:48 PM, jkpl wrote:
On Wednesday, 18 March 2015 at 23:41:41 UTC, Walter Bright wrote:
On 3/18/2015 5:45 AM, CraigDillabaugh wrote:
You said that "Unfortunately" this thinking is going out of style
"for good
reasons". I am confused (sorry, I am at work, and didn't have time
to watch
the 1+ hour video you linked to - maybe some clues were there)!
Consider this C code:
#include <stdbool.h>
#include <stdio.h>
typedef long T;
bool find(T *array, size_t dim, T t) {
int i;
for (i = 0; i <= dim; i++);
{
int v = array[i];
if (v == t)
return true;
}
}
There are several bugs in it. I've showed this to probably over 1000
programmers, and nobody found all the bugs in it (they are obvious
once pointed out). It is not easy to write bug free loop code, and
find() is a trivial function.
just for fun:
1/ '<=' instead of '<'
2/ array should be tested against null before entering the loop
3/ 'int v' instead of 'T v'
Got them all ?
4. The semicolon after the for loop's closing paren...
5. No return if the item isn't found, leading to undefined behavior.
There may well be more, but I'll stop spamming this topic. Sorry Walter.