Hacker News new | past | comments | ask | show | jobs | submit login

That code snippet is a matryoshka doll of brainfuck.



The first thing I thought of is, even in a hypothetical world without a Clear() method or any means of adding one, why use a for loop instead of a while loop? And if you are set on a for loop, why not simply set the first count to a variable? It is bad on multiple levels.


    <list of dead items>
"I need to delete every item"

    for (i = 0; i < length; i++) {
        remove item[i];
    }
"Shit, that didn't work. Why isn't it deleting everything?

    for (i = 0; i < length; i++) {
        printf("%d", item[i]); 
        remove item[i];
    }
"Huh, it's removing every other item."

    for (i = 0; i < length; i++) {
        printf("%d, %d", item[i], i); 
        remove item[i];
    }
"Weird, it's removing an item, skipping an item, then removing the next one."

    for (i = 0; i < length; i++) {
        printf("%d, %d", item[i], i); 
        remove item[i];
        i--;
    }
"Well shit, that seemed to work."

    for (i = 0; i < length; i++) {
        remove item[i];
        i--;
    }
"Ship it."




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: