Robert C. Martin, during his keynote at QCon London 2010, tried to figure out why there is so much bad code written. He offers advice on writing good code talking about a bad code example, Boy Scout rule, functions, arguments, craftsmanship, TDD, continuous integration, pairing, small cycles, patterns, engineering, certification, and other elements contributing to qualitative code.

http://www.infoq.com/presentations/Robert-C.-Martin-Bad-Code