• simon.crick (9/25/2013)


    "embrace the idea that code can be wrong" -- Nathan Marz

    Surely this is the wrong approach, as it just gives people an excuse to be lazy.

    If they're lazy, they won't be good developers, whether they embrace this or not. If they are proud and professional, they won't be lazy, but they'll be more realistic and more open to correcting issues.

    Code should NEVER be wrong. It is not difficult to write code that works correctly. You just need to follow two simple rules:

    1) Be crystal clear about the valid set of inputs, and throw an appropriate exception if the input is not in the valid set.

    2) If you are not sure whether the logic is correct, break your code into smaller functions/procedures until it is 100% clear that it will work correctly in all cases.

    Bugs only arise when people do not follow these simple rules.

    Simon

    I'd disagree, but you're also conflating working with right. Code can compile and run, but work as intended. I might be able to enter orders in the system and store them in a database, but might not calculate the shipping date correctly, or I might not anticipate that I need defaults in certain fields. I'll make mistakes coding because you cannot be crystal clear about all inputs for all situations.

    Bugs also arise as code gets very complex, and when platforms have their own bugs. If it were as simple as just paying attention to all details, we wouldn't have bugs in most software. There are many, many smart people writing software. We still get bugs.